Android 将应用程序活动设置为接受操作。查看操作
当用户点击按钮时,发生以下代码:Android 将应用程序活动设置为接受操作。查看操作,android,android-activity,Android,Android Activity,当用户点击按钮时,发生以下代码: Uri web = Uri.parse("http://www.google.com"); Intent i = new Intent(Intent.ACTION_VIEW,web); startActivity(i); 它运行正常,在默认web浏览器中打开网站。但我正在尝试显示菜单,如果您安装了更多能够显示网页的应用程序,则会显示该菜单。 因此,我使用以下AndroidManifest文件准备了空白应用程序FakeBrowser: <?xml vers
Uri web = Uri.parse("http://www.google.com");
Intent i = new Intent(Intent.ACTION_VIEW,web);
startActivity(i);
它运行正常,在默认web浏览器中打开网站。但我正在尝试显示菜单,如果您安装了更多能够显示网页的应用程序,则会显示该菜单。
因此,我使用以下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"));
更多信息:
更新:
在你的舱单上:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
是的,此部件缺失。但结果仍然是一样的。当我点击按钮时,并没有任何选择对话框,页面在默认浏览器中打开。所以我在FakeBrowser应用程序的AndroidManifest.Xml中仍然有一些错误?我已经编辑了答案。让我知道它是否适合你