Custom URL Schema for Cordoba

I’m trying to find a good document on the topic “How to set up a custom URL scheme for the Cordova application (on iOS and Android platforms)”.

I spent hours on the Internet, but could not find a good answer. I have some links that are related but not very helpful to me.

Mine is a Cordova application that runs on iOS and Android platforms. I need to enable my application to run after calling the url from email (ex: Myapp: //).

Please tell me what configuration changes should I make to the Cordoba 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>
+4
source share
2 answers

, , , FYI , ( !) :

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

, URL, :

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

, . Android iOS.

+4

Android:

:

      <activity
            android:name=".MainActivity"
            android:label="@string/activity_name"
            android:launchMode="singleTask"
            <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="yourappscheme"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>

Android: launchMode = "singleTask"

singleTask singleTop . .

iOS:

enter image description here

, " " href "yourappscheme://".

<a href="yourappscheme://">Open my app</a>

, Scheme, host.

, URL-, .

, URL- : yourappscheme://? username = "xxx@gmail.com" Android:   OnCreate.

Intent intent = getIntent();
Uri data = intent.getData();
if(data!=null) { //
    //get schma
    String scheme = data.getScheme(); // 
    Toast.makeText(getActivity(), scheme, Toast.LENGTH_LONG).show();
    if(scheme.contains("yourappscheme")) {
        //get parameter
        String urltextboxname = data.getQueryParameter("username");
        system.out.println(urltextboxname) // it will print xxx@gmail.com
    }
}

iOS: :

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    if (!url) {
        return NO;
    }

    // calls into javascript global function 'handleOpenURL'
    NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
    [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

    // all plugins will get the notification, and their handlers will be called
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
    NSString *myUrlString = [url absoluteString];
    if ([myUrlString containsString:@"yourappscheme://"])
    {
        NSLog(@"Calling Application Bundle ID: %@", sourceApplication);
        NSLog(@"URL scheme:%@", [url scheme]);
        NSLog(@"URL query: %@", [url query]);
    }
    return YES;
}

, .

+1

All Articles