Open a Url with option of Installed App and Browser in Android - android

I have a String url. The requirement : On Click of a Button, the default chooser should open if the deeplinked App is installed with the User else opens the browser.
I am doing this onClick of the Button:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url);
startActivity(i);
The onClick opens the browser only, evenif the deeplinked App is installed. What should be the approach?

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url);
startActivity(i);
The above code worked in case of deep-linked URL. The default chooser gave option for the App.

Related

How to open links in browser from the app?

I am developing an android application. I am currently opening a new activity with WebView when the user click on a URL. I want to change it load the URL inside the the browser. How is that possible?
Simply do like this.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(intent);

Open link for installation on Facebook

I have an Android application. I can add posts to timeline using it. Every such post is signed with message "via ЖАЛОБАнк" below. When I click to this link, open page for this app.
How make opening Google Play or other page in browser for installation this app?
You can start an intent to open a link when the user clicks on it. For instance, you can do this onClick()
Intent fb = new Intent(Intent.ACTION_VIEW);
fb.setData(Uri.parse("http://facebook.com"));
startActivity(fb);
I didn't try but this should work:
Intent intent = new Intent("android.intent.action.VIEW", Uri
.parse("https://play.google.com/store/apps/details?id=com.facebook.katana"));
startActivity(intent);

Intent to launch a website from activity doesn't work after 2-3 times

I have a webview activity and button to open a website in default browser after user clicks on
show more button.I destoy the webview activity after launching the browser intent as shown in the code below.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
finish()
My problem is,
i) After launching 2-3 websites using the intent it stops loading the website in the browser
ii) Sometimes it launches the browser on click of button but loads previous url which was opened in the browser.
iii)I tried setting Intent.FLAG_ACTIVITY_CLEAR_TOP for intent but it does not help.
Let me know what I am doing wrong.

How can I load a webpage with Google chrome instead of WebView in Android?

I want to let the user to visit my website by click a button.
However, I want the app to open the google chrome or other external web browser to open the website instead of load the url with WebView.
How can I do that?
You can do it with an ACTION_VIEW Intent --
Uri myUri = Uri.parse("http://www.whereever.com/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(myUri);
startActivity(intent);
If you want to do it on a button click, you will need to put it in the onClick method of your onClickListener.

How to open local html file in default browser

I can open my local html file with android browser by following way:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(webPageUri, "text/html");
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(intent);
And it works. But I would like to open my local html file in default browser without specifing:
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
Is there a way to to that?
Edit:
If I remove setClassName as you suggest, it opens in HtmlViewer (it is not a default browser).
And if I do it like that:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(webPageUri);
startActivity(intent);
I get: ActivityNotFoundException
Just use:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(webPageUri, "text/html");
startActivity(intent);
This will give the user a list of installed browsers to choose from. If there is only one browser, then that's the one that will be launched.
Just remove the setClassName() line and you are set to go.
This will launch the default browser if it is the only browser in the phone. If there are more than one, the user will have to select one.

Categories

Resources