2014-02-28 20 views
0

我已正確設置所有內容,但隱式活動未顯示應用程序選擇器,它表示沒有應用程序可以執行此操作(該URL是我想要打開的內容用戶選擇的應用程序)如何在Android中製作應用程序選擇器

這裏是我的MyBrowser xml文件:

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

這裏是代碼創建的意圖和initalizing的appChooser:

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) 
    Intent viewer = new Intent(Intent.ACTION_VIEW,Uri.parse(URL)); 


    // 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(viewer, CHOOSER_TEXT); 

    Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction()); 
    // TODO - Start the chooser Activity, using the chooser intent 
    startActivity(chooserIntent); 

} 

我很困惑,因爲代碼對我來說看起來很清楚,但我不能爲了我的生活找出它爲什麼不起作用。

+0

我認爲選擇器會直接轉發意圖,如果只有一個應用程序來處理它。 – flx

+0

嗯,我試圖讓它使用Android的默認瀏覽器和MyBrowser作爲選擇,因爲它是一個網站地址。 – MrTimotheos

回答

0

對於瀏覽器,你可以使用這個意圖過濾器(添加意圖過濾器標籤): 意圖過濾

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

試試這個

0

你確定將MyBrowser應用程序安裝到設備上?如果沒有安裝,那顯然是行不通的。除此之外,我不確定你需要<category android:name="android.intent.category.DEFAULT" />部分到你的過濾器。通常你只需要一個類別,兩個似乎是過度殺傷...

+0

我已經解決了這個問題。我沒有安裝myBrowser ......大聲笑。此外,有指示隱式啓動它。 – MrTimotheos

相關問題