2017-01-02 58 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); 

我觉得代码中直接打开一个浏览器,其安装在手机中的弹出窗口。你不会为此编写特定的代码。

相关问题