0

My app wants to open a web link (like https://www.google.com) by means of this method:

public void openUrl(Activity activity, String urlParam) {
    String url = Uri.encode(urlParam);
    Intent browserIntent = new Intent(Intent.CATEGORY_BROWSABLE, Uri.parse(url));

    browserIntent.setAction(ACTION_VIEW);

    activity.startActivity(browserIntent);
}

I'm getting this error:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.google.com }

If I make the app call the chooser for the user to select an application, a message appears on the device saying that no app can handle the action.

startActivity(Intent.createChooser(intent, "Browse with"));

So, this also does not work.

This is very strange, I see a lot of similar questions but no solution. The URL is correct.

This is the Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

How is it possible? I have another application that uses a similar code and it is able to call a browser to display the URL on the same device.

Here's its Gradle file:

apply plugin: 'android'

android {
    //noinspection GradleCompatible
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.myappname.app"
        versionCode 62

        minSdkVersion 19
        targetSdkVersion 28
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:28.0.0'
}

How to solve the issue?

OhhhThatVarun
  • 3,981
  • 2
  • 26
  • 49
P5music
  • 3,197
  • 2
  • 32
  • 81
  • Does this answer your question? [How can I open a URL in Android's web browser from my application?](https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application) – Md. Asaduzzaman Feb 03 '20 at 11:39
  • Also check this [No Activity found to handle Intent : android.intent.action.VIEW](https://stackoverflow.com/questions/5882656/no-activity-found-to-handle-intent-android-intent-action-view/6225478) – Md. Asaduzzaman Feb 03 '20 at 11:41
  • @Md. Asaduzzaman My url is correct, I do not understand how to solve. – P5music Feb 03 '20 at 11:41
  • Removing this `String url = Uri.encode(urlParam);` resolve the problem – Md. Asaduzzaman Feb 03 '20 at 11:53

2 Answers2

2

Actual issue is with the usage of Uri.encode(urlParam). You are encoding your URL but later you are not decoding it for the ACTION_VIEW to understand the intent data!

    String url = "https://www.google.com/";
    String query = Uri.encode(url, "UTF-8");
    Intent browserIntent = new Intent(CATEGORY_BROWSABLE, Uri.parse(Uri.decode(query)));
    browserIntent.setAction(ACTION_VIEW);
    startActivity(browserIntent);
buzzingsilently
  • 1,546
  • 3
  • 12
  • 18
0
Uri uri = Uri.parse("https://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

I got the same error android.content.ActivityNotFoundException: No Activity found to handle Intent

The problem was because I didn't have any app that can open URLs (i.e. browsers) installed in my phone. So after Installing a browser the problem was solved.

Make sure there is at least one app which handles the intent you are calling

Swati
  • 146
  • 1
  • 10