我使用此代码可以显示已安装的浏览器应用程序:
Log.i(TAG, "Entered startImplicitActivation()");
// TODO - Create a base intent for viewing a URL
// (HINT: second parameter uses Uri.parse())
Intent baseIntent = null;
baseIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
// TODO - Create a chooser intent, for choosing which Activity
// will carry out the baseIntent
// (HINT: Use the Intent class' createChooser() method)
Intent chooserIntent = Intent.createChooser(baseIntent, "Choose App");
// TODO - Start the chooser Activity, using the chooser intent
Log.i(TAG, "Chooser Intent Action:" + chooserIntent.getAction());
startActivity(chooserIntent);
但是它将直接在默认浏览器应用程序中打开链接。为什么?
我创建并安装了另一个简单的浏览器应用程序,它具有以下功能intent-fiilter
:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent-filter>
您的仿真器只有一个可以接受此类Intent的应用,在您的情况下,仅存在一个浏览器,因此可以直接重定向。
尝试通过一次添加默认类别并检查EDIT
<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" />
</intent-filter>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句