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.
Related
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);
I have an Android SDK that uses a web view to show some pages, but depending on the requested link, I have it open an external browser. I am using the WebView's shouldOverrideUrlLoading method, and if it's a link to be opened externally, I use:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
This works for us in a demo app, but someone integrating our SDK says that it's opening within the web view. I don't have access to their code, but what is the developer able to do on his side to prevent the default action to open an external browser? I have thought of two possible solutions that I found on SO:
Use some flags to make sure no existing tasks are used, like so:
Intent i = new Intent(Intent.ACTION_VIEW);
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
i.putExtras(b);
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.setData(Uri.parse(url));
startActivity(i);
Would this be sufficient?
Another solution is to force opening in the chrome browser, like so:
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
context.startActivity(intent);
What would be the preferable solution? Or am I missing anything else?
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.
My code to open url in browser is
private void openBrowserUrl(String url) {
Intent i = new Intent(Intent.ACTION_VIEW);
System.out.println("============Url==================" + url);
i.setData(Uri.parse(url));
startActivity(i);
unlock(UNLOCK_TO_HOME);
}
Above is working fine when there is no pattern lock.
But When I tried to open browser after pattern lock, url value remain blank.
I have custom lock screen in my application.. When phone is locked, after that, I tried to unlock the phone at that time custom lock screen is opened by my application. and in that I have written this code. I got url value and it successfully passes to browser.
But, I tried with above process with patter lock(default lock system of android)
then the flow is
custom lock screen-->open url code(got the url value)-->default pattern lock-->browser without url value.
In above flow, when pattern lock is there, browser unable to get url which I have passed.
This problem occurs on api > 21. There been some changes in the KEYGUARD, and after you unlock the screen there is some kind of a delay or something that makes the intent not to react,buy using the flags it should delay the intent and make it work
the code here should solve the problem.
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("your url"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(i);
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.