【问题标题】:Android app link only works from adbAndroid 应用链接仅适用于 adb
【发布时间】:2017-02-09 21:58:07
【问题描述】:

我希望在单击具有特定自定义方案的链接时启动我的应用程序。 但它只适用于 adb:

./adb shell a start -a Android.Intent.Action.VIEW -d "ghd://whateversite.com"

点击链接,或者直接在浏览器中写入URL时不起作用。

我正在使用:

    <activity
        android:name=".link.LaunchActivity"
        android:theme="@android:style/Theme.NoDisplay">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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="ghd" />
        </intent-filter>
    </activity>

【问题讨论】:

  • 那你是怎么解决的?

标签: android android-intent


【解决方案1】:

在 Intent 过滤器中也设置android:host

<activity
    android:name=".link.LaunchActivity"
    android:noHistory="true"
    android:theme="@android:style/Theme.NoDisplay">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />

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

        <data android:scheme="ghd" android:host="whateversite.com" />
    </intent-filter>
</activity>

【讨论】:

  • 您好,感谢您的回复。但实际上,“whateversite.com”可以是whateversite :) 唯一会一直存在的部分是方案 ghd。
【解决方案2】:

尝试从您的&lt;intent-filter/&gt; 中删除autoVerify=true。正如documentation 中所说:

当 android:autoVerify 属性存在时,安装您的应用会导致系统尝试验证与您应用的所有意图过滤器中的 Web URI 关联的所有主机。仅当系统成功验证清单中声明的​​所有应用链接模式时,系统才会将您的应用视为指定 URI 模式的默认处理程序。

由于您没有添加任何主机,这可能是它不起作用的原因。

【讨论】:

  • 你是对的,它没有意义。我删除了它,但行为是一样的。谢谢!
  • 这很奇怪,因为我现在有完全相同的东西,而且它只是工作......在你的例子中,你正在使用“mdw”方案,而你的 adb 命令正在使用“ghd” ,但我认为这不是问题所在,我可能是印刷错误。
  • 它是 :P 所以在你的情况下,当你直接在浏览器中编写它时它才有效?
  • 我只尝试用这个方案打开一个链接。我从未尝试通过在浏览器的状态栏上键入链接来直接打开链接。也许您应该尝试创建一个带有引用此方案的链接的页面
猜你喜欢
  • 1970-01-01
  • 2019-07-31
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多