Answer the question
In order to leave comments, you need to log in
How to open URL programmatically?
The code is like this:
public void open_browser(String url){
PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : list) {
ComponentName comp = new ComponentName(resolveInfo.activityInfo.packageName, "com.android.browser.BrowserActivity");
intent.setComponent(comp);
startActivity(intent);
break;
}
}
Answer the question
In order to leave comments, you need to log in
private void openExtUrl(String url) {
final Uri parsedUri = Uri.parse(url);
PackageManager packageManager = getPackageManager();
Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
// Create intent to show chooser
Intent chooser = Intent.createChooser(browseIntent, "Open url with ..");
if (browseIntent.resolveActivity(packageManager) != null) {
startActivity(chooser);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question