ala*_*how 5 android android-intent
我正在为站点创建应用程序,并创建了链接重定向器活动(仅适用于 http://*.domain.com url),如果 url 支持,则重定向到活动。如果不支持应该在浏览器中打开链接。它工作正常,但是当用户设置应用程序默认应用程序时,单击活动选择器中的始终按钮,应用程序进入循环。活动打开,检查链接支持,如果不支持带Intent.ACTION_VIEW标志的打开意图,则活动再次打开。
问题: 如何在浏览器中打开链接(可能是默认值),而不是我的应用程序,为 url 设置默认值。
我尝试在浏览器中打开 url 的方法:
private void unsupportedLink() {
Toast.makeText(this, R.string.unsupported_link, Toast.LENGTH_LONG).show();
Intent openUrl = new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()));
startActivity(openUrl);
finish();
}
Run Code Online (Sandbox Code Playgroud)
清单中的活动:
<activity
android:name=".util.UrlHandler"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<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="http"
android:pathPattern="/.*"
android:host="m.domain.com" />
<data
android:scheme="http"
android:pathPattern="/.*"
android:host="www.domain.com" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1701 次 |
| 最近记录: |