I\'ve been trying to find out how to create an intent that will open the user\'s preferred browser without specifying the URL. I know how to open it by giving a specific URL
Uri uri = Uri.parse("www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, "Open with");
startActivity(chooser);
This code creates an intent to open user specified browser.
This is a late answer, but looks like this functionality is available in API 15:
Intent browser = Intent.makeMainSelectorActivity(
Intent.ACTION_VIEW,
Intent.CATEGORY_APP_BROWSER);
startActivity(browser);
Docs for makeMainSelectorActivity
Try this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_BROWSER);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent.createChooser(intent, "Select Browser"));
}
else { //Popup a msg so as to know the reason of not opening the browser
Toast.makeText(this, "There is no Browser App", Toast.LENGTH_LONG).show();
}
Worked for me, hope for you also!
The homepage URL specified by the user will be stored in the preferences for whichever browser app they're using. With Androids 'sandbox' model for apps, you'll have no access to this unless the app has a Content Provider which allows access. In addition, the content provider will differ between the browser apps and you'll have a hard time covering the ones that do exist.
Have you tried opening to a web page which attempts to update the users homepage URL through the use of JavaScript?
Here's how I did it:
String packageName = "com.android.browser";
String className = "com.android.browser.BrowserActivity";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
mHomeActivity.startActivity(internetIntent);
If you have no homepage set, it'll open a blank page (at least in Android 2.1).
Use below code
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com"));
Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
if (sendIntent.resolveActivity(getPackageManager()) != null)
startActivity(chooser);