【问题标题】:Intent.action.VIEW does not work on some devicesIntent.action.VIEW 在某些设备上不起作用
【发布时间】:2017-11-27 20:07:13
【问题描述】:

单击电子邮件、消息或浏览器应用程序中的 URL 链接时,我需要打开我的应用程序。因此,请参阅我的代码以了解此功能:

<activity
    android:name=".ui.main.MainActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <intent-filter>
        <data android:scheme="https" />
        <data android:scheme="https" android:host="www.mysite.org"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.APP_EMAIL"/>
        <category android:name="android.intent.category.APP_MESSAGING"/>
        <category android:name="android.intent.category.APP_BROWSER"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

此代码已足够,适用于某些移动设备,尤其是 Android 版本 5.0、6.0 和 7.0 的设备,但不适用于版本 7.1 和 8.0。为什么会这样?是权限问题吗?

【问题讨论】:

  • 你的Intent怎么样?
  • @MuratK。当用户从 gmail 中单击链接 (mysite.org) 时,我需要打开我的应用程序。

标签: android android-intent intentfilter


【解决方案1】:

例如:您的网址将类似于 https://example.com 并且您在 Android Manifest 中有如下意图过滤器:

<activity
    android:name="com.droid.MainActivity"
    android:label="@string/app_name" >

    <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:host="example.com"
            android:scheme="https" />
    </intent-filter>
</activity>

使用 URL 映射 编辑器通过 Android 应用链接(Android Studio > 工具 > Android 应用链接)轻松地将 URL 意图过滤器添加到您的活动。

【讨论】:

    【解决方案2】:

    看完changes in Android O我得出的结论是问题描述如下

    URI 不能包含空标签。此前,该平台支持 接受主机名中的空标签的解决方法,这是非法的 URI 的使用。此解决方法是为了与旧的 libcore 兼容 发布。错误使用 API 的开发人员会看到 ADB 消息:“URI example..com 在主机名中有空标签。这是 格式错误,将不会在未来的 Android 版本中被接受。” Android 8.0 移除了这个变通方法;系统返回 null 为 格式错误的 URI。

    因此请尝试将android:label="string resource" 添加到您的intent-filter 语法中,以便用户可以在替代菜单中看到它。

    【讨论】:

    • 所以实际上是缺少标签!只是为了让人们知道他们将来是否会寻找它
    猜你喜欢
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多