Android Custom URL to open App like in iOS

后端 未结 3 707
轻奢々
轻奢々 2020-12-02 10:58

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

相关标签:
3条回答
  • 2020-12-02 11:09

    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);
       }
    }
    
    0 讨论(0)
  • 2020-12-02 11:17

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

    0 讨论(0)
  • 2020-12-02 11:18

    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

    0 讨论(0)
提交回复
热议问题