gpt4 book ai didi

android - 如何启动和 App Chooser

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:31 30 4
gpt4 key购买 nike

此应用程序的任务是隐式激活一个单独的应用程序来查看 URL“http://www.google.com”。因此,App Chooser 应该会出现,让我在至少两个浏览器之间进行选择:默认浏览器会显示 www.google.com 网站,另一个简单的“浏览器”只会显示 url。 问题是 - 当我使用隐式 Activity 时,应用选择器没有出现。可能我为第二个“简单浏览器”编写了错误的 Intent 过滤器。

private void startImplicitActivation() {

Log.i(TAG, "Entered startImplicitActivation()");

// TODO - Create a base intent for viewing a URL
// (HINT: second parameter uses parse() from the Uri class)
Uri adress = Uri.parse(URL);
Intent intentUrlView = new Intent(Intent.ACTION_VIEW, adress);

// TODO - Create a chooser intent, for choosing which Activity
// will carry out the baseIntent. Store the Intent in the
// chooserIntent variable below. HINT: using the Intent class'
// createChooser())
Intent chooserIntent = Intent.createChooser(intentUrlView, CHOOSER_TEXT);
//chooserIntent = null;

Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
// TODO - Start the chooser Activity, using the chooser intent
if (intentUrlView.resolveActivity(getPackageManager()) != null) {
startActivity(chooserIntent);
}
}

list

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.labs.intentslab.mybrowser"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyBrowserActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />
</activity>
</application>

最佳答案

似乎是 Adam Porter 的第三周作业为 Android 手持系统编写移动应用程序。无论如何,我希望你有你的解决方案在 AndroidManifest.xml 中,您需要再添加三个 Intent 过滤器。

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

此外,如果您无法运行 AndroidUnit 测试,

确保您在隐式按钮调用的 ActionListener 中完成了类似的操作。

Intent baseIntent = new Intent(Intent.ACTION_VIEW);
baseIntent.setData(Uri.parse(URL));

Intent chooserIntent = Intent.createChooser(baseIntent, "Select Application");

Coursera 已有邮件列表。请使用它。

关于android - 如何启动和 App Chooser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800948/

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