MaFt
MaFt

Reputation: 478

Android Custom URL to open App like in iOS

I can add a link to, for example, 'navigon://' on a website that, in iOS devices, will open up the Navigon app if it is installed.

Is there a similar simple method to open an app from a website (assuming it's installed) in Android?

Upvotes: 31

Views: 96679

Answers (3)

CoolMind
CoolMind

Reputation: 28783

See Everything you need to know about implementing iOS and Android Mobile Deep Linking. This is a good article for Android and iOS.

You may already have known that there are Deep Links, and starting from Android 6.0 Android App Links appeared. The latter are intended to open an URL only in your application, not any other competing. For instance, reddit.com can be opened in 7 applications, if not use this verification.

enter image description here

You can associate every needed Activity with links from which it should be opened. For instance, if you wish to open in the application links like https://awesomejobs.com/jobs/{id}, you need to add these lines to AndroidManifest.xml:

<activity android:name="com.awesomejobsapp.ui.activity.JobActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT" />

        <data android:scheme="https"
              android:host="awesomejobs.com"
              android:pathPrefix="/jobs" />
    </intent-filter>
</activity>

Then in JobActivity write (a code is received from an article in Russian):

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.ac_job);

   final Intent intent = getIntent();
   final String action = intent.getAction();
   final String data = intent.getDataString();

   if (Intent.ACTION_VIEW.equals(action) && data != null) {
      final String jobId = data.substring(data.lastIndexOf("/") + 1);
      loadJobDetails(jobId);
   }
}

Upvotes: 1

DeaMon1
DeaMon1

Reputation: 581

Android deep linking: Add an intent filter to your manifest

<activity
android:name="com.example.android.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_title_viewgizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
    <data android:scheme="http"
          android:host="www.example.com"
          android:pathPrefix="/gizmos" />
    <!-- note that the leading "/" is required for pathPrefix-->
    <!-- Accepts URIs that begin with "example://gizmos”
    <data android:scheme="example"
          android:host="gizmos" />
    -->
</intent-filter>

https://developer.android.com/training/app-indexing/deep-linking.html

Upvotes: 21

Aman Aalam
Aman Aalam

Reputation: 11251

Check out intent filters in Android. Check out the Category specially.

Upvotes: 6

Related Questions