簡體   English   中英

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

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

我想知道我必須如何配置我的應用程序才能使用android-app://application.id打開它?

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

URI_ANDROID_APP_SCHEME似乎不像文檔那樣工作。 相反,Chrome 和 Firefox 只打開一個market://鏈接到我的應用程序。

對於 Chrome,我找到了一個僅描述intent://方案的文檔

當意圖過濾器包含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>

你必須在你的組件的intent-filter添加<data../>描述 URI,像這樣,

<intent-filter>
   ...

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

並在您的網站部分定義這樣的意圖

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

更新。 沒有意識到該方案是保留方案,盡管我的解決方案適用於您定義的任何方案。 我查找了 Intent 類的來源,似乎您必須像這樣定義 URI

android-app://your_package

或者

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

Androids Intent 類中parseUri方法的第一行

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

值得一提的是:這個方案是在 API 22 上添加的。

我已經測試過它可以與標簽一起a ,並且正如@tynn 在評論中提到的那樣,也適用於window.open()location.href並且不能在 Chrome 的地址欄中工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM