Search code examples
javaandroidandroid-studioandroid-intentandroid-activity

Trying to open chrome app with a URL link from another android app


I am trying to open a website with chrome app from my android app. However, i am not getting any response each time i click the button which link to the code below:

public void openWebsite(View view) {

    //Get the url text
    String url = mWebsiteEditText.getText().toString();

    //Parse the URI and create the intent
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

    //Find an activity to hand the intent and start that activity.
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }else{
        Log.d("ImplicitIntents","Cant handle this");
    }
}

i learned and follow the code from here https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#3 and below is some of the message i noticed in the Logcat in android studio when i click the button to open the link:

2020-08-08 01:21:23.651 767-2753/system_process I/AppsFilter: interaction: PackageSetting{cc102 com.example.implicitintents/10160} -> PackageSetting{bbc8e62 com.android.chrome/10129} BLOCKED

2020-08-08 01:21:23.652 31691-31691/com.example.implicitintents D/ImplicitIntents: Cant handle this

The app should open chrome just as shown here: https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#5

Pardon me if the question i asked is duplicated.


Solution

  • I think you might be missing some things in your manifest file. Did you follow this part of the tutorial? What does yours look like?

    https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#6

    in particular this part:

    <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" 
                                android:host="developer.android.com" />
        </intent-filter>
    

    also I think you will need the internet permission to access websites so I would add this too:

    <uses-permission android:name="android.permission.INTERNET" /> 
    

    What permission do I need to access Internet from an Android application?

    Hope this helps a bit!