此應用程序的任務是隱式激活一個單獨的應用程序來查看URL「http:// www.google.com」。所以,應用選擇器應該出現,並讓我至少在兩個瀏覽器中進行選擇:默認的瀏覽器會顯示www.google.com網站,另一個簡單的「瀏覽器」會向我顯示網址。 問題是 - 應用程序選擇器不會出現,當我使用隱式活動。可能我爲第二個「簡單瀏覽器」寫了錯誤的意圖過濾器。如何啓動和應用選配器
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>
所以這是來自馬里蘭州Android課程第一部分coursera ... –