How to open links in browser from the app? - android

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);

Related

Open a Url with option of Installed App and Browser in 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.

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);

Can i launch Android Browser with Robotium?

I am new for Robotium. I am trying to launch Android Browser with Robotium. Thanks!
You can do it this way:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().getContext().startActivity(i);
However it will open another application and you will not be able to do anything else with robotium.
Robotium can be used for accessing views inside the application. Since browser is another application you cannot access it.
Only you can just launch a browser using the following code
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Context instrumentationContext=getInstrumentation().getContext();
instrumentationContext.startActivity(browserIntent);

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.

Open url in browser and force page reload

I use the following code to open an URL in browser:
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
startActivity(intent);
But if the page behind the url was already opened in browser, running the above code doesn't refresh the page. How could I force page refreshing?
Looking for an answer as well... this seems to work for me:
Uri url = Uri.parse(website+"?time="+(new Date().getTime()));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(url);
activity.startActivity(i);
because the new get parameter forces a reload.
to my knowledge you cannot force it to refresh from the Android side (unless you're showing it in your own WebView) You'd have to set the page itself to auto refresh, that would presumably ensure whatever is being shown is likely to be up to date.

Categories

Resources