Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom URL scheme for Cordova

I am trying to find out a good document on "How to define custom URL scheme for a Cordova app(on both iOS and Android platforms)".

I have spent hours on internet but couldn't find a good answer. I got some links which are related but not helping me much.

Mine is a Cordova app which runs on iOS and Android platforms. I need to enable my app to be started upon invoking a URL from email(ex: Myapp://).

Please advise me what configuration changes should I maketo my Cordova app to enable this feature.

EDIT: Android manifest

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.simple.app" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <data android:scheme="com.test.simple" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

Url

<a href="com.test.simple://">Launch The App</a>
like image 586
Mathews Avatar asked Jun 23 '15 09:06

Mathews


1 Answers

I know that you are specifically asking for documentation about how to hand-code this yourself, but just FYI there is a nice plugin that will do all of the (considerable amount of!) work for you:

https://github.com/EddyVerbruggen/Custom-URL-scheme

When you install it, you just provide the URL scheme that you want to use to launch your app:

$ cordova plugin add https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git --variable URL_SCHEME=myCustomUrlScheme

And that's pretty much all there is to it. Works on Android and iOS.

like image 140
Mike Dailor Avatar answered Nov 03 '22 09:11

Mike Dailor