将应用程序活动设置为接受操作.VIEW操作



当用户点击按钮时,会发生以下代码:

Uri web = Uri.parse("http://www.google.com");
Intent i = new Intent(Intent.ACTION_VIEW,web);
startActivity(i);

它运行正常,在默认的网络浏览器中打开网站。但我正在尝试显示菜单,如果你安装了更多能够显示网页的应用程序,就会出现菜单。所以我用这个AndroidManifest文件准备了空白应用程序FakeBrowser:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pavel.fakebrowser" >
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <data android:scheme="http" android:host="google.com"/>
            <category android:name="android.intent.category.BROWSABLE" />
            <action android:name="android.intent.action.VIEW" />
        </intent-filter>
    </activity>
</application>

我试图设置第二个意向过滤器标签,这样我的应用程序就会接受这个浏览器请求,但它仍然会立即打开默认浏览器。请你告诉我,我做错了什么?谢谢

您必须使用IntentChooser:

Uri web = Uri.parse("http://www.google.com");
Intent i = new Intent(Intent.ACTION_VIEW,web);
startActivity( Intent.createChooser(i, "Choose Application"));

更多信息:http://developer.android.com/training/basics/intents/sending.html

更新:在你的舱单上:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http"/>
        </intent-filter>

最新更新