android.intent.action.VIEW 无法打开我的应用程序

问题描述 投票:0回答:1

我正在尝试为用户设置功能,以使用 Android 相机应用程序扫描二维码以打开我的 Android 应用程序。如果用户没有安装我的应用程序,后备方法是打开一个网页,提示他们安装它。

我的 Android 清单中有这个:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https"/>
        <data android:scheme="http"/>
        <data android:host="myhost" />
    </intent-filter>

如果我跑步

adb shell am start -d https://myhost

我在 Android 设备上收到提示,询问我是否要使用应用程序或 Chrome 打开链接,这很棒。

但是,如果我跑

adb shell am start -W -a android.intent.action.VIEW -d https://myhost

(指定 VIEW 作为操作)它在 Chrome 中打开网页,并返回以下内容:

Starting: Intent { act=android.intent.action.VIEW dat=https://myhost... }
Status: ok
LaunchState: COLD
Activity: com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity
TotalTime: 349
WaitTime: 351
Complete

同样,如果我使用 Android 相机扫描具有相同 URL 的二维码,它会在 Chrome 中打开网页。

因此,即使我在意图过滤器中明确有

android.intent.action.VIEW
,它也会在 chrome 中打开链接,而不是打开我的应用程序。

知道我做错了什么吗? Stack Overflow 上还有一些其他人提出了类似的问题,但他们使用的是具有不寻常格式的自定义方案,而我只是使用普通的旧 https。

android android-intent
1个回答
0
投票

您需要指定您的应用程序的包。

假设您的应用程序的包名称是

com.example.myapplication

然后运行命令如下

adb shell am start -a android.intent.action.VIEW -d "https://myhost" "com.example.myapplication"
© www.soinside.com 2019 - 2024. All rights reserved.