How to open phonegap app from unique domain url? - web

I am trying to develop an app for my web site using phonegap. So I need to ask
'Would you like to open this link from app?'
When someone opens my web's url in app installed device like facebook urls. How can I do that?

I only had to google this: open cordova app from url
Took me 30 seconds at most.
You can add this onto your config.xml:
<preference name="AndroidLaunchMode" value="singleTask" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="example.com" android:scheme="http" />
</intent-filter>
As well as this onto your index.html:
function deviceReady() {
window.plugins.webintent.getUri(function(url) {
console.log("INTENT URL: " + url);
//...
});
}
window.plugins.webintent.onNewIntent(function(url) {
console.log("INTENT onNewIntent: " + url);
});
Note: This is not my code. Found it at how can cordova open app from http or https url?

Related

Problems with GoRouter deeplink paths when app is not deployt under root

I want to host an Flutter Web App under https://www.someDomain.com/someFolder/otherFolder
and create a deeplink like that https://www.someDomain.com/someFolder/otherFolder/showProducts/1
that should also work for smartphones.
In android I define:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="www.someDomain.com" android:path="/someFolder/otherFolder" />
</intent-filter>
So the deeplink is working for the webapp and the smartphone - BUT I would have to define a GoRoute like that:
GoRoute(
path: "**someFolder/otherFolder/**showProducts/:productID",
builder: _showProductsDL,
),
The problem is that a version of the WebApp could also be deployed under other subfolder structures like
https://www.someDomain.com/
or
https://www.someDomain.com/somewhereElse/V2/
or
https://www.someDomain.com/somewhereElse/v3/
Is it somehow possible to handle all by defininig a GoRoute with the path "showProducts/:productID" and ignore the subfolders / remoe them from the path the GoRouter is working with?

Android Studio (Ionic Gradle) - App isn't installed after Building

Problem After building, running in Android-Studio-Emulator: "App isn't installed".
What to do?
--Android Studio 2020.3
--Android SDK 30, Tools 30.0.2
--Gradle 7.0.2
...
I fail to see any proper Log in the emulator, maybe it's just me but coming from XCode this Android Studio is very poorly built, too bad. Hope someone can help.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.midix.finance">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name="com.midix.finance.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/custom_url_scheme" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
</application>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Camera, Photos, input file -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Geolocation API -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<!-- Navigator.getUserMedia -->
<!-- Video -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Audio -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
</manifest>
Android studio is not poorly built. You need to learn its UI/UX and its functions just like how you learnt xCode.
I recommend debug your app in physical device. So connect your phone to the computer using USB cable (USB debugging must be turned on in your device).
Your device name must show in the place where Pixel 2 API 30 showing in your Android Studio screen.
Click on play button next to the device. After gradle building, app will be installed on your device. Authenticate your installation in your phone (Something says "Install this app?") after clicking play button.
Open "Logcat" option at the bottom to see any serious error logs coming.
If your app not installed means search the Logcat with your App package name. It will show why app not installed. Post your Logcat error to get accurate solution.

Host NextJs to IIS

Good Day!
My colleague has a website node.js (next.js), his website works fine when we build and start thru console (npm run build and npm start).
We have hosted it in a Azure VM (Windows Server 2016 IIS, iisnode and urlrewrite installed), we created a pipeline and we are able to get the artifacts (".next" folder when we run the build) and deploy it to IIS however we still need a manual interaction to place the web.config. Below is the web.config
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="service-worker.js" verb="*" modules="iisnode" />
</handlers>
<!-- use URL rewriting to redirect the entire branch of the URL namespace
to hello.js node.js application; for example, the following URLs will
all be handled by hello.js:
http://localhost/node/express/myapp/foo
http://localhost/node/express/myapp/bar
-->
<rewrite>
<rules>
<rule name="AMS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
But when we visit the website, it throws an error of 403 that need to supply the default page. (I'm lost here and not able to run his website thru IIS)
Note: His other website works fine (because it has a service-worker.js).
Anyone experience deploying the Next.JS to IIS? Thanks in Advance.
In the /public folder, create the following web.config to accept requests from /a/b/c and rewrite them to / where our NextJs code lives.
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="NextJs Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Just doing this should allow you to reload a page on a route like /products, but NextJs will render /, ie, the index page, because that's what our rewrite rule told it to deliver.
So, we need to create a body Component that takes a NextRouter as a prop then compare the window's url to the router's url. If they don't match, we need to change our client side route with router.push().
I'm using TypeScript so my body.tsx is
import * as React from 'react';
import { NextRouter } from 'next/router';
export default class Body extends React.Component<{router : NextRouter}>
{
componentDidMount()
{
if (window.location.pathname == this.props.router.pathname) return;
this.props.router.push(global.window.location.pathname);
}
render = () => this.props.children;
}
Then in _app.tsx, we simply need to wrap the main Component in our Body Component.
import { useRouter } from 'next/router'
import Head from 'next/head';
import Body from '../src/components/elements/body';
function MyApp({ Component, pageProps }) {
const router = useRouter();
return (
<>
<Head>
<title>NextJs on IIS</title>
</Head>
<Body router={router}>
<Component {...pageProps} />
</Body>
</>
)
}
export default MyApp
Run npm run build, and copy the /out folder to your IIS server.

Random HTTP 5xx errors from IISnode

I'm working on the Botbuilder framework using the NODEjs SDK and i have the current setup for directline conversations
A nodejs web UI which is a chat interface for the bot
A nodejs bot logic server
Both these servers are hosted in an azure web app (windows server 2016) with an IIS-node webserver
Currently the server containing the bot logic has the below routes (using the restify framework)
server.post('/receiveMessage', connector.listen());
server.post('/beginSpecialDialog', function(req,res,next){
var _body = req.body;
logger("info", "server", "/beginSpecialDialog triggered", null, {"conversationId": _body._directlineAddress.conversation.id})
if(_body._directlineAddress.secret !== config.BOT.DIRECTLINE_SECRET){
logger("warn", "server", "directline credentials do not match", null, {"conversationId": _body._directlineAddress.conversation.id, "secretSent":_body._directlineAddress.secret, "err":err});
res.send(401);
}
bot.beginDialog(_body._directlineAddress, _body._dialogId, _body._specialParams, function(err){
if(err){
logger("warn", "server", "error occured on starting main dialog from url", null, {"conversationId": _body._directlineAddress.conversation.id, "err":err});
res.send(400, {"err": err.stack });
}
else{
res.send(200);
}
});
});
The /beginSpecialDialog is initiated by the webUI server whenever we need to convey the bot to start a special Dialog for the webUI browser.
However , sometimes (1 in every 10 requests or so) - this route isnt being processed by the bot server. I get a 5xx response from the bot server with the below details
</head>
<body>
<div id="content">
<div class="content-container">
<h3>HTTP Error 500.1013 - Internal Server Error</h3>
<h4>The page cannot be displayed because an internal server error has occurred.</h4>
</div>
<div class="content-container">
<fieldset><h4>Most likely causes:</h4>
<ul> <li>IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.</li> <li>IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.</li> <li>IIS was not able to process configuration for the Web site or application.</li> <li>The authenticated user does not have permission to use this DLL.</li> <li>The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>Things you can try:</h4>
<ul> <li>Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.</li> <li>Check the event logs to see if any additional information was logged.</li> <li>Verify the permissions for the DLL.</li> <li>Install the .NET Extensibility feature if the request is mapped to a managed handler.</li> <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>Detailed Error Information:</h4>
<div id="details-left">
<table border="0" cellpadding="0" cellspacing="0">
<tr class="alt"><th>Module</th><td> iisnode</td></tr>
<tr><th>Notification</th><td> ExecuteRequestHandler</td></tr>
<tr class="alt"><th>Handler</th><td> iisnode</td></tr>
<tr><th>Error Code</th><td> 0x0000006d</td></tr>
</table>
</div>
<div id="details-right">
<table border="0" cellpadding="0" cellspacing="0">
<tr class="alt"><th>Requested URL</th><td> https://test-bot-website:80/server.js</td></tr>
<tr><th>Physical Path</th><td> D:\home\site\wwwroot\server.js</td></tr>
<tr class="alt"><th>Logon Method</th><td> Anonymous</td></tr>
<tr><th>Logon User</th><td> Anonymous</td></tr>
</table>
<div class="clear"></div>
</div>
</fieldset>
</div>
<div class="content-container">
<fieldset><h4>More Information:</h4>
This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.
<p>View more information ยป</p>
<p>Microsoft Knowledge Base Articles:</p>
</fieldset>
</div>
</div>
</body>
</html>
heres the log from the IIS node webserver
2018-01-25 06:22:58 TEST-BOT-WEBSITE POST /beginSpecialDialog X-ARR-LOG-ID=da648f30-dda9-4103-8a48-862b65eef82d 443 - 23.102.157.162 - - - test-bot-website.azurewebsites.net 500 1013 109 298 1425 120540
Could anyone shed some light as to why this happens? heres my web.config file
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- BEGIN rule TAG FOR WWW and HTTP to HTTPS REDIRECT -->
<rule name="First_Secure" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}" />
</rule>
<rule name="Second_Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="ON" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" ignoreCase="false" />
</conditions>
<action type="Redirect" url="https://{C:2}" />
</rule>
<!-- END rule TAG FOR WWW and HTTP to HTTPS REDIRECT -->
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!--This redirects home page to /public/index.html-->
<rule name="DefaultDocRewrite" stopProcessing="True">
<match url="^$" />
<action type="Rewrite" url="/public/index.html" />
</rule>
<!--This redirects all urls to public -->
<rule name="StaticContentRewrite">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<!--This catches if the file exists under public directory and stops processing, so that iis will serve static files -->
<rule name="StaticContent" stopProcessing="True">
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
<add input="{REQUEST_URI}" pattern="^/public/" />
</conditions>
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!-- Runs node processes on each core you have in the machine -->
<iisnode watchedFiles="web.config" nodeProcessCountPerApplication="0"/>
</system.webServer>
</configuration>

Android Studio Error Type 3: Error while Launching activity

I am new to android development and I really find it all messy and confusing at times. I was running My project which worked alright before then Copied an activity and changed the package name which worked fine. I closed the android studio. Now when I opened my project again I started getting the error "Error while launching:: No default Activity found" but I had it in AndroidManifest.xml. Then I tried the "Edit Configuration-> General ->Launch app and set it to Splashscreen. Now I am getting this new error which is too stubborn to disappear ! I have tried everything but nothing really worked for me. Kindly help me out I may be missing something stupid.
$ adb shell am start -n"com.example.dell.optasiaapp/com.example.dell.optasiaapp.Splashscreen" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.example.dell.optasiaapp/com.example.dell.optasiaapp.Splashscreen" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat= [android.intent.category.LAUNCHER] cmp=com.example.dell.optasiaapp/.Splashscreen }
Error type 3
Error: Activity class {com.example.dell.optasiaapp/com.example.dell.optasiaapp.Splashscreen} does not exist.
Error while Launching activity
What I have tried:
Clean project and rebuild
Uninstalling app, disconnecting the mobile and reconnecting to build again
Deleting.idea/workspace.xml
adding Application id = "Pakage name" in gradle build
Changing android:name=".Splashscreen" to android:name="com.example.dell.optasiaapp.Splashscreen"
File -> Invalidate Caches / Restart...
My AndroidManifest code is
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"></application>
<activity android:name=".Splashscreen"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeScreen">
<intent-filter>
<action android:name="com.example.dell.optasiaapp.HomeScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name=".AboutUs">
<intent-filter>
<action android:name="com.example.dell.optasiaapp.AboutUs" />
<category android:name="android.intent.category.About" />
</intent-filter>
</activity>
<activity android:name=".Help" > </activity>
This is so stupid. I tried everything available on Internet but nothing worked for me. So I just made a new project and copy pasted every code to the new empty activities. It runs fine now.
If you change the package name manually, try this:
In build.gradle change
apply plugin: 'android-library'
to
apply plugin: 'com.android.application'
One of the worst things that I have faced in Android Studio.
Follow following steps:
Close your Android Studio.
Delete .idea/workspace.xml
Launch Android Studio and launch your application.
I was having the same problem, emulating the app and trying in other phones worked perfect, only with my phone was failing.
Something that work for me was deleting all other user profiles, including the guest user.

Resources