【问题标题】:Android Custom URL to open App like in iOSAndroid 自定义 URL 可以像在 iOS 中一样打开应用程序
【发布时间】:2011-07-01 06:15:16
【问题描述】:

我可以在一个网站上添加一个链接,例如“navigon://”,如果安装了该应用程序,在 iOS 设备中将打开该应用程序。

是否有类似的简单方法可以在 Android 中从网站(假设已安装)打开应用程序?

【问题讨论】:

标签: android html ios


【解决方案1】:

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

【讨论】:

  • 如何获取完整的 URL(我正在尝试从 URI 中获取参数)
  • 您可以使用intent.getDataString() 来获取完整的url。参考stackoverflow.com/a/1609662/2641380
  • 这仅适用于 http/https 协议。它不适用于自定义协议,例如 @Tim Castelijns 的问题中的 navigon://
  • ` ` 非常重要,我在邮递员中尝试 url apit-testing 并想知道为什么相同的 url 它没有打开在 android 中,用于 stripe-terminal-android-app。
【解决方案2】:

在 Android 中查看 intent filters。专门查看类别。

【讨论】:

  • 谢谢,但那是指使用 Android SDK 编写应用程序。我需要一种从网页“a”链接打开应用程序的方法,例如 Open Navigon 如果安装在 iOS 设备上会打开 Navigon 应用程序。
  • 哦,当然有办法,我一到家就告诉你。现在,我得跑了。
  • 以下是在 Android 设备上调用 Google Apps 的方法:developer.android.com/guide/appendix/g-app-intents.html 不过,下面的链接也不错。
【解决方案3】:

Everything you need to know about implementing iOS and Android Mobile Deep Linking。这是一篇适用于 Android 和 iOS 的好文章。

你可能已经知道有Deep Links,并且从Android 6.0开始Android App Links出现了。后者旨在仅在您的应用程序中打开 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 中写入(收到来自article 的俄语代码):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    相关资源
    最近更新 更多