Intent.action.VIEW 不适用于某些设备
Intent.action.VIEW does not work on some devices
单击电子邮件、消息或浏览器应用程序中的 URL Link 时,我需要打开我的应用程序。因此,请参阅我的此功能代码:
<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。为什么会这样?是不是权限问题?
看完changes in Android O我得出的结论是问题描述如下
URIs cannot contain empty labels. Previously, the platform supported a
workaround to accept empty labels in host names, which is an illegal
use of URIs. This workaround was for compatibility with older libcore
releases. 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."
Android 8.0 removes this workaround; the system returns null for
malformed URIs.
因此请尝试将 android:label="string resource"
添加到您的 intent-filter
语法中,以便用户可以在替代菜单中看到它。
例如:您的 url 将类似于 https://example.com 并且您在 Android 清单中具有意图过滤器,如下所示:
<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 Link 时,我需要打开我的应用程序。因此,请参阅我的此功能代码:
<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。为什么会这样?是不是权限问题?
看完changes in Android O我得出的结论是问题描述如下
URIs cannot contain empty labels. Previously, the platform supported a workaround to accept empty labels in host names, which is an illegal use of URIs. This workaround was for compatibility with older libcore releases. 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." Android 8.0 removes this workaround; the system returns null for malformed URIs.
因此请尝试将 android:label="string resource"
添加到您的 intent-filter
语法中,以便用户可以在替代菜单中看到它。
例如:您的 url 将类似于 https://example.com 并且您在 Android 清单中具有意图过滤器,如下所示:
<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 应用程序链接)。