【发布时间】:2014-02-15 17:19:36
【问题描述】:
此应用程序的任务是隐式激活一个单独的应用程序来查看 URL,“http://www.google.com”。所以,App Chooser 应该会出现,让我在至少两个浏览器之间进行选择:默认的一个,它将显示 www.google.com 站点,另一个简单的“浏览器”,它只显示 url。 问题是 - 当我使用隐式活动时,应用程序选择器不会出现。 可能我为第二个“简单浏览器”编写了错误的意图过滤器。
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);
}
}
清单
<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>
【问题讨论】:
-
这是来自 coursera 上的马里兰 Android 课程第一部分...
标签: android