I want to open some links in an external browser. Before opening, I want to display the list of browsers on the device. I did this functionality using Intent.ACTION_VIEW. But as per my app's requirement, I want to display the list of browsers even if there is only one browser application on the device. Does anyone have any idea about this? Thanks.
If you have one browser application , the chooser will not launched , the URL will be loaded on that browser application. If you have two or more browser applications, the android system launch an IntentChooser the show the list of all browser apps installed on the device , so the user can choose his preferred browser to load the URL :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
EDIT :
to create your custom Intent Chooser :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getString(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
refer this
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.maidofknowledge.com"));
Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
settings>apps>clear default (
this is if you have previously set "use as default app" for chrome
these 2 images are my source:
Message to select browser or select default:
http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-03.jpg
Clear default browser, show intent chooser again:
http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-02.jpg
Related
I currently use this
Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://www.google.com"));
startActivity(intent);
It currently opens in my default browser.
But I need it to open like this.
Is there any simple way to do that?
If you want to open any specific browser application rather then opening the url on default browser. Set component to your implicit intent for an example if you want to open the URL only on chrome application then you can call it like this:
String url = "https://www.google.com";
try {
Intent i = new Intent("android.intent.action.MAIN");
i.setComponent("com.android.chrome/com.android.chrome.Main");
i.addCategory("android.intent.category.LAUNCHER");
i.setData(Uri.parse(url));
startActivity(i);
} catch(ActivityNotFoundException e) {
// Google chrome application is not installed in user's phone
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
Sometimes it may happen that application is not available on user's phone in that case catch the exception and open the default browser.
I was trying to create a chooser to grant users freedom to open a pdf file with the application they prefer.
Here's my approach:
private void openPdf(String pdfUrl, String mime) {
// Intent pdfViewIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Intent pdfViewIntent = new Intent(Intent.ACTION_VIEW);
pdfViewIntent.setDataAndType(Uri.parse(pdfUrl), mime);
Log.d(TAG, "openPdf: uri: " + Uri.parse((pdfUrl)));
Intent chooser = Intent.createChooser(pdfViewIntent, "Choose an app");
// chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // optional
startActivity(chooser);
finish();
}
The pdf url is something like this: https://drive.google.com/file/d/.../view?usp=sharing
And for the mime type, I tried using both "application/vnd.google-apps.document" and "application/pdf".
Now, when the user clicks on document, I get an output like the following:
But I want an output like the following screenshot: (it appears when I try to open the same link with WhatsApp)
NOTE 1: using WebView is not a good option for me.
NOTE 2: the above approach works if the URL is in the format https://example.com/.../filename.pdf. But it fails for Google Drive's link.
I want to do a menu where u can choose the audio apps that are installed in your phone (like Youtube, Music, Skype...) so I donĀ“t know the exactly name of this type of menu (if this have a special name).
This should be what you are searching for: https://developer.android.com/training/basics/intents/sending.html
Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null) {
startActivity(launchIntent);
}
Replace com.package.address with the package name of the application you want to open.
If I understand, you would to send file to another app based on type of this file.
This code allows to send audio file to selected app.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(Intent.createChooser(intent, "Choose app"));
More info
Can anyone help me in Code for opening links in external browsers or other Android app?
Now the case is the link is opening in the app itself. But if the link belongs to an android app its not opening. It's showing install the Android app.
So I want that if the link can be opened in browsers, then it will ask from a list of browsers. Or if the links belongs to an app it must show the app in the list too.
Something like this could work
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
startActivity(browserIntent);
As #zain posted ago you can use.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
But if you have more then one browser installed in device and want to choose from one of them. Use intent chooser like this
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
refer from here
Show browser list when opening a link in android
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.co.in/"));
String title = "Complete Action Using";
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
If you are in a WebView in your App, and on clivking a link there, if the app opens the link in the App Itself, Then possibly u should have overridden this method.
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
//view.loadUrl(url);
return false;
}
});
The return of false should ask the user, where to Open the link. With the browsers installed in the mobile
Hi
I want to write an app to call default browser and redirect to a designated url.
Any suggestion to 1)call the default browser, 2)redirect to a designated url.
Thanks
you just want to launch an ACTION_VIEW intent with the Uri of the webpage as your data element :
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("http://www.bbc.co.uk"));
startActivity(httpIntent);
To open the default browser use an Intent with the action VIEW. To tell the browser which page to load us the data-part of the Intent.
Example:
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com"));
startActivity(browse);
Since this is a basic task in Android you might want to read some basics about Intents in Android.