2017-01-02 144 views
0

我正在開發一個Android Coursera作業,以使用隱式意圖在瀏覽器中打開鏈接。在代碼中,我有一個選擇器方法,可以讓用戶選擇使用哪種瀏覽器。但問題是沒有使用CATEGORY Browsable選項的瀏覽器。請看看我的代碼:意圖在瀏覽器中打開不工作的鏈接

private void startImplicitActivation() { 

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

     // TODO - Create a base intent for viewing a URL 
     // (HINT: second parameter uses Uri.parse()) 


     String url = "https://www.google.com"; 
     Intent baseIntent = new Intent(Intent.CATEGORY_BROWSABLE, Uri.parse(url)); 


     // TODO - Create a chooser intent, for choosing which Activity 
     // will carry out the baseIntent 
     // (HINT: Use the Intent class' createChooser() method) 
     Intent chooserIntent = new Intent(Intent.createChooser(baseIntent, "Select Your Browser")); 


     Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction()); 


     // TODO - Start the chooser Activity, using the chooser intent 
     startActivity(chooserIntent); 


} 

在活動啓動時產生的輸出低於(我不明白爲什麼沒有瀏覽器上來):

createChooser() method called with intent

+1

[發送意向到瀏覽器以打開特定URL]可能的重複(http://stackoverflow.com/questions/3004515/sending-an-intent-to-browser-to-open-specific-url) – AxelH

回答

0

您可以使用此:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("your url")); 
startActivity(intent); 

我覺得代碼中直接打開一個瀏覽器,其安裝在手機中的彈出窗口。你不會爲此編寫特定的代碼。

相關問題