简体   繁体   中英

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?

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

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

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.

在此输入图像描述

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);
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM