Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide and handle deep links in cordova / phonegap applications

Hi I would like to know of a Cordova / Phonegap plugin or way to expose and handle deep-links in my Sencha Touch / Cordova App

So far I am able to deep-link into other applications lets say open Google Play to a specific app detail page.

Using this plugin https://github.com/code4jhon/org.apache.cordova.startapp

So what I would like to do is enable other applications to open specific views or functionalities in my application. I would like to support Android and IOS.

So bottom line is there a Cordova plugin to expose Activities for Android and their counterparts on IOS ?

Or how to achieve this?

Looked into Cordova docs but didn't find anything... any help, doc link would be very much appreciated.

like image 899
code4jhon Avatar asked Aug 01 '14 03:08

code4jhon


People also ask

How do you handle deep links?

Setup on Android​ To configure the external linking in Android, you can create a new intent in the manifest. The easiest way to do this is with the uri-scheme package: npx uri-scheme add mychat --android . If you want to add it manually, open up SimpleApp/android/app/src/main/AndroidManifest.

How do I create a deep link for an app?

In the Link Settings and Redirects section, after you enable the link for iOS, Android, or both, fill out the following fields: "If the app is not installed go to" (this is the fallback redirect) "If the app is already installed, go to: (deep link)" "After installation, go directly to: (deferred deep link)"

What are deep links with example?

A Deep Link is a URL link that is generated, when anyone clicks on that link our app will be open with a specific activity or a screen. Using this URL we can send a message to our app with parameters. In WhatsApp, we can generate a deep link to send a message to a phone number with some message in it.


2 Answers

I was able to accomplish this using Branch Metrics. They are a new startup and super fantastic.

Check out their cordova plugin docs for deep links here:

https://github.com/BranchMetrics/Branch-PhoneGap-Cordova-SDK#initialize-sdk-and-register-deep-link-routing-function

I recommend reading all their docs to get a feel of what to do. However, with Ionicframework and AngularJS, I built a service you could use in your application:

https://gist.github.com/sean-hill/627fa40f96577baae378

After building your project with Branch's plugin, follow these steps for iOS and Android configuration.

iOS

Add this to your .plist file:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourappname</string>
        </array>
    </dict>
</array>

Then cordova build ios; cordova emulate ios. To check if it is working, open your emulator, go to Safari and type in yourappname:// and see if it redirects to your app.

Android

Add this to your AndroidManifest.xml file after building android:

<intent-filter>
    <data android:scheme="yourappname" android:host="open" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Add this to your config.xml file:

<preference name="AndroidLaunchMode" value="singleTask" />

Then build again and you should be on your way to great deep linking success!

As per @Deminetix request, this is how I close the Branch session.

document.addEventListener("pause", function(){
    var branch = window.Branch;
    branch.closeSession();  
}, false);

Have fun coding :)

like image 128
sean-hill Avatar answered Oct 16 '22 21:10

sean-hill


You can try https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin

It worked perfectly for me.

remember to clean/build after installation

You can handle variable implementing handleOpenURL

function handleOpenURL(url) {
  console.log("received url: " + url);
}
like image 14
mentat Avatar answered Oct 16 '22 21:10

mentat