gpt4 book ai didi

android - 应用选择器 Intent 没有出现在 Android 模拟器中

转载 作者:行者123 更新时间:2023-11-30 02:36:14 25 4
gpt4 key购买 nike

我使用这段代码显示已安装的浏览器应用程序:

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 ,在你的情况下只有一个浏览器存在所以它直接重定向。

尝试添加一次默认类别并检查编辑

   <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>

关于android - 应用选择器 Intent 没有出现在 Android 模拟器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26478748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com