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?