How do i use intent in android widget to open images in browser.
If the image is on the internet it would be as simple as this:
String url = "http://www.picturesnew.com/media/images/image-background.jpg";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
However if the image is inside of your assets you can't open it in the browser. That's because the browser accepts URI data that starts with http. Furthermore the browser is a separate app and one app can't use other apps assets.
You could dipslay the image through the use of a WebView though.
To open a website from your widget:
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.fakesite.com\articles"));
startActivity(intent);
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'm doing Android application which I want to open an HTML file from my application data on Chrome browser without manual interrupt. Currently it's working fine for default browser.But I want to open it on chrome browser.
My Code for default browser:
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.fromFile(file));
browserIntent.setType("text/html");
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(browserIntent);
How could I proceed that on Chrome browser explicitly.If I tried like setClassName("com.android.chrome", "com.android.chrome.Main"), I'm getting exception as
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW..." .
Please help me to get out this issue. Is there any other way?Thanks.
Set classname as
com.android.chrome/com.google.android.apps.chrome.Main
browserIntent.setClassName("com.android.browser", "com.android.chrome/com.google.android.apps.chrome.Main");
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
I try to download a file through the browser. it's working perfectly if a have that :
String pdfUrl = "www.myLink.com/document/test.pdf";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdfUrl));
startActivity(intent);
However if the link is :
String pdfUrl = "www.myLink.com/document/test/";
It's very odd because it works on my browser "Chrome". I can download the 2 files....
Using the URL without the full file name will not work, because the Intent system does not know the type of the resource behind the URI - it will probably launch a browser pointed to that address instead of a PDF viewer. What you could do, however, is explicitly specify the content type behind your URL by using intent.setDataAndType() instead of intent.setData(), like this:
String pdfUrl = "www.myLink.com/document/test/";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(pdfUrl), "application/pdf");
startActivity(intent);
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.