【问题标题】:I am creating a Browser App but Android won't detect my app in chooser while I click on any URL我正在创建浏览器应用程序,但当我单击任何 URL 时,Android 不会在选择器中检测到我的应用程序
【发布时间】:2020-07-28 19:19:18
【问题描述】:

我正在创建一个浏览器应用程序,我希望 Android 将我的应用程序视为浏览器并显示在要打开的应用程序选择器中。

我希望我的应用显示在此列表中。

这是我的清单活动代码:

<activity
        android:name=".Activity.LinkDetectorActivity"
        android:exported="true"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <data android:scheme="testscheme" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

【问题讨论】:

  • 浏览器是什么意思?
  • 我正在尝试创建一个类似 chrome 或 edge 的应用
  • “我希望 android 将我的应用程序视为浏览器”——这是什么意思?
  • 你不需要上网权限?
  • 每当用户通过 WhatsApp、Facebook 等应用点击链接时,Android 都会提示用户选择浏览器,我希望将我的应用添加到所有已安装浏览器的列表中。

标签: android intentfilter android-intent-chooser


【解决方案1】:

用下面替换你的意图过滤器,

 <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http"/>
        <category android:name="android.intent.category.DEFAULT" />
        <!-- The BROWSABLE category is required to get links from web 
        pages. -->
        <category android:name="android.intent.category.BROWSABLE" />
 </intent-filter>

</activity>

【讨论】:

  • 更新了答案。还请检查您点击的网址?是http还是https?如果是 https 则也添加该方案。
【解决方案2】:

尝试将testcheme更改为“http”和“https”

<activity
    android:name=".Activity.LinkDetectorActivity"
    android:exported="true"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <data android:scheme="http" />
        <data android:scheme="https" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
  • 2016-08-29
  • 2015-07-12
相关资源
最近更新 更多