我可以在网站上添加一个链接,例如'navigon://',在iOS设备上,如果安装了Navigon应用程序,则会打开Navigon应用程序。
在Android中是否有类似的简单方法来打开已安装的应用程序从网站上?
我可以在网站上添加一个链接,例如'navigon://',在iOS设备上,如果安装了Navigon应用程序,则会打开Navigon应用程序。
在Android中是否有类似的简单方法来打开已安装的应用程序从网站上?
Android深度链接:在你的清单文件中添加一个意图过滤器
<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
在Android中查看意图过滤器,特别是查看类别。
请查看实现iOS和Android移动深度链接所需的一切。这是一篇适用于Android和iOS的好文章。
您可能已经知道有深度链接,从Android 6.0开始出现了Android应用链接。后者旨在仅在您的应用程序中打开URL,而不是任何其他竞争对手。例如,如果不使用此验证,reddit.com可以在7个应用程序中打开。
您可以将每个需要的Activity
与应该打开它的链接关联起来。例如,如果您希望在应用程序中打开像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>
然后在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);
}
}