简体   繁体   English

Intent.action.VIEW在某些设备上不起作用

[英]Intent.action.VIEW does not work on some devices

I need to open my application when clicked the URL Link in E-mail, Message or Browser applications. 单击电子邮件,消息或浏览器应用程序中的URL链接时,我需要打开我的应用程序。 So, see the my code for this feature: 因此,请参见此功能的代码:

<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>

This code is sufficient and works on some mobile devices, especially devices with android versions 5.0, 6.0 and 7.0 but does not work on versions 7.1 and 8.0 . 此代码已足够,并且可以在某些移动设备上使用,尤其是在具有Android 5.0、6.0和7.0版本的设备上但是在7.1和8.0版本上不能使用。 Why does this happen? 为什么会这样? Is it a permission problem? 这是权限问题吗?

Ex: Your url will be something like https://example.com and you have the intent filter in Android Manifest as below: 例如:您的网址将类似于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>

Use the URL Mapping editor to easily add URL intent filters to your Activities with Android App Links (Android Studio > Tools > Android App Links). 使用URL映射编辑器可以通过Android应用链接(Android Studio>工具> Android应用链接)轻松地将URL目的过滤器添加到您的活动中。

After reading changes in Android O I came to the conclusion that the problem is described as follows 阅读了Android O中的更改后,我得出的结论是,问题描述如下

URIs cannot contain empty labels. URI不能包含空标签。 Previously, the platform supported a workaround to accept empty labels in host names, which is an illegal use of URIs. 以前,该平台支持一种变通方法,可以接受主机名中的空标签,这是URI的非法使用。 This workaround was for compatibility with older libcore releases. 该解决方法是为了与较早的libcore版本兼容。 Developers using the API incorrectly would see an ADB message: "URI example..com has empty labels in the hostname. This is malformed and will not be accepted in future Android releases." 错误地使用API​​的开发人员会看到ADB消息:“ URI example..com的主机名中包含空标签。此文件格式不正确,在以后的Android版本中将不被接受。” Android 8.0 removes this workaround; Android 8.0删除了此替代方法; the system returns null for malformed URIs. 系统针对格式错误的URI返回null。

So try adding android:label="string resource" to your intent-filter syntax so the user will see it in the alternatives menu. 因此,请尝试将android:label="string resource"到您的intent-filter语法中,以便用户在替代菜单中看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用不会与intent.action.VIEW一起安装 - Android app does not install with intent.action.VIEW 没有找到处理意图的活动{act=android,intent.action.VIEW} - No activity found to handle intent{act=android,intent.action.VIEW} 动作视图意图不起作用 - Action view intent does not work 具有Crashlytics-Beta的单个Activity intent.action.VIEW导致同时运行两个App实例 - Single Activity intent.action.VIEW with Crashlytics-Beta causing two instances of App running at same time 在 Worker 中以意图启动活动在某些设备上不起作用 - Starting activity with an intent in a Worker does not work on some devices 我已经创建了一个默认的拨号器应用,并且ACTION_CALL意图在某些设备上不起作用 - I have created a default dialer app and the ACTION_CALL intent doesn't work on some devices startActivity(intent)在某些设备中不起作用 - startActivity(intent) doesn't work in some devices Intent Extras仅在某些设备上有效 - Intent extras only work on some devices 为什么 Intent.ACTION_MAIN 在某些设备上需要 android.permission.MANAGE_USERS? - Why does Intent.ACTION_MAIN require android.permission.MANAGE_USERS on some devices? 该程序不适用于某些设备 - The program does not work on some devices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM