繁体   English   中英

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

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

我正在研究Android Coursera作业,以使用隐式意图在浏览器中打开链接。 在代码中,我有一个选择器方法,它提供一个选项供他们选择要使用的浏览器。 但是,问题在于,没有使用“类别可浏览”选项的浏览器出现。 请看一下我的代码:

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()方法

您可以使用此:

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

我认为该代码直接打开弹出窗口,提示您手机中安装了哪些浏览器。 您无需为此编写特定的代码。

暂无
暂无

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

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