简体   繁体   English

在 Android 上使用 Chrome 打开 android-app 方案

[英]Open android-app scheme with Chrome on Android

I was wondering how I'd have to configure my app to open it with android-app://application.id ?我想知道我必须如何配置我的应用程序才能使用android-app://application.id打开它?

adb shell am start android-app://application.id

The URI_ANDROID_APP_SCHEME seems not to work as documented. URI_ANDROID_APP_SCHEME似乎不像文档那样工作。 Instead Chrome and Firefox only open a market:// link to my app.相反,Chrome 和 Firefox 只打开一个market://链接到我的应用程序。

For Chrome I found a documentation only describing the intent:// scheme.对于 Chrome,我找到了一个仅描述intent://方案的文档

When the intent filter contains the DEFAULT and BROWSABLE category it works with Firefox .当意图过滤器包含DEFAULTBROWSABLE类别时,它适用于Firefox

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

You have to add <data../> describing URI in intent-filter for your component, like so,你必须在你的组件的intent-filter添加<data../>描述 URI,像这样,

<intent-filter>
   ...

   <data android:scheme="android-app"/>
</intent-filter>

and on your site part define intent like this并在您的网站部分定义这样的意图

intent:#Intent;scheme=android-app;package=your_package;end

UPDATE.更新。 Didn't realize that scheme was a reserved one, although my solution works for any scheme you define.没有意识到该方案是保留方案,尽管我的解决方案适用于您定义的任何方案。 I looked up the sources of the Intent class it seems you have to define your URI like this我查找了 Intent 类的来源,似乎您必须像这样定义 URI

android-app://your_package

OR或者

android-app://your_package/ 
#Intent;action=com.example.MY_ACTION;end

First line of the parseUri method in the Androids Intent class Androids Intent 类中parseUri方法的第一行

final boolean androidApp = uri.startsWith("android-app:");

Worth to mention: This scheme was added on API 22.值得一提的是:这个方案是在 API 22 上添加的。

I've tested it works with a tag, and as @tynn mentioned in the comments also for window.open() and location.href and not working from the address bar in Chrome.我已经测试过它可以与标签一起a ,并且正如@tynn 在评论中提到的那样,也适用于window.open()location.href并且不能在 Chrome 的地址栏中工作

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

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