简体   繁体   English

Android自定义URL,用于在iOS中打开App

[英]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. 我可以在一个网站上添加一个链接,例如“navigon://”,在iOS设备中,如果安装了Navigon应用程序,它将打开它。

Is there a similar simple method to open an app from a website (assuming it's installed) in Android? 是否有类似的简单方法从Android网站(假设已安装)打开应用程序?

Android deep linking: Add an intent filter to your manifest Android深层链接:为您的清单添加一个intent过滤器

<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 https://developer.android.com/training/app-indexing/deep-linking.html

Check out intent filters in Android. 查看Android中的意图过滤器 Check out the Category specially. 特别查看类别。

See Everything you need to know about implementing iOS and Android Mobile Deep Linking . 查看有关实施iOS和Android Mobile Deep Linking的所有信息 This is a good article for Android and iOS. 这是Android和iOS的好文章。

You may already have known that there are Deep Links , and starting from Android 6.0 Android App Links appeared. 您可能已经知道有Deep Links ,并且从Android 6.0 Android App Links开始出现。 The latter are intended to open an URL only in your application, not any other competing. 后者仅用于在您的应用程序中打开URL,而不是任何其他竞争对手。 For instance, reddit.com can be opened in 7 applications, if not use this verification. 例如,如果不使用此验证,reddit.com可以在7个应用程序中打开。

在此输入图像描述

You can associate every needed Activity with links from which it should be opened. 您可以将每个所需的Activity与应从中打开的链接相关联。 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 : 例如,如果您希望在https://awesomejobs.com/jobs/{id}等应用程序链接中打开,则需要将这些行添加到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): 然后在JobActivity写一个代码(从俄语文章中收到):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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