簡體   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