简体   繁体   English

打算在浏览器中打开链接不起作用

[英]Intent to open a link within a browser not working

I'm working on an Android Coursera assignment to open a link within a browser using Implicit Intents. 我正在研究Android Coursera作业,以使用隐式意图在浏览器中打开链接。 Within the code, I have a chooser method that gives one the option of which browser they would like to use. 在代码中,我有一个选择器方法,它提供一个选项供他们选择要使用的浏览器。 The problem though is that no browser appears using the CATEGORY Browsable option. 但是,问题在于,没有使用“类别可浏览”选项的浏览器出现。 Please look at the my code: 请看一下我的代码:

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);


 }

The resulting output when launched in an activity is below (I don't understand why no browsers come up): 在活动中启动时的结果输出如下(我不明白为什么没有浏览器出现):

用故意调用的createChooser()方法

You can use this: 您可以使用此:

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

I think the code directly opens the popup that which browsers is installed in your phone. 我认为该代码直接打开弹出窗口,提示您手机中安装了哪些浏览器。 You don't write specific code for that. 您无需为此编写特定的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM