Menu Search Me

How to use cordova plugin customurlscheme?

Reference

https://www.npmjs.com/package/cordova-plugin-customurlscheme 

How to use

Step 1 add cordova-plugin-customurlscheme to your project

cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=ierbuster

Step 2 What does cordova-plugin-customurlscheme put into your index.html?

After running step 1 above, note the following changes in your index.html file:

<script type="text/javascript" src="js/plugins/LaunchMyApp.js"></script>

Step 3 Add your own javascript code into your index.html

Add the following to your index.html file -  the function will be called by android/java/nl/xservices/plugins/LaunchMyApp.java's onNewIntent(Intent intent) function:

var mah_mobile_customurl = null;
function handleOpenURL(url) {
console.log("receivedurl: " + url);
mah_mobile_customurl = url;
console.log("mah_mobile_customurl="+mah_mobile_customurl);
}

Step 4 AngularJS special handling

If you are using AngularJS, your AngularJS controller/service functions will be called BEFORE  variable mah_mobile_customurl is set by function handleOpenURL.

What you can do in this case is:

  1. Start a timer your controller/service
  2. Have the timer check the value of mah_mobile_customurl and perform the necessary action when it is not null

Step 5 AndroidManifest.xml file

If you follow Step 1 to add the plugin into your project, the following change will be made into your AndroidManifest.xml file:

<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="ierbuster" />
</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:host=" " android:pathPrefix="/" android:scheme=" " />
</intent-filter>

Step 6 How to invoke your Android mobile app

You can have something like the following html link to invoke your mobile app:

<!DOCTYPE html>
<html>
<head>
<title>Busting Insufficient Effort Responses</title>
</head>
<body >
<a href="ierbuster://somepath?code=bar">the destination</a>
</body>
</html>