I am opening a url in android webview which is redirecting the user to google play store web page in android webview and play store page is showing OPEN IN PLAY STORE APP
and while clicking that button rather then opining play store app webview is redirecting to a web url which is not found.
Now i don't know why it is happening as in google chrome app same scenario is working fine. Please suggest the better solution.
Some code i have done :
mWebView.loadUrl("https://play.google.com/store/apps/details?id=in.org.npci.upiapp&hl=en")
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
return super.shouldOverrideUrlLoading(view, urlNewString);
}
#Override
public void onPageFinished(WebView view, String url) {
}
});
Note: I am using this play store url just as an example.
You need to override shouldOverrideUrlLoading, but you must also inspect the URL and conditionally create an intent if it starts with the intent:// scheme. We (the Android WebView team) have written a sample application which does precisely this.
Just put this data in the webview:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("https://play.google.com/store/apps/developer?id=putyourplaystoreid")) {
Intent i = new Intent("android.intent.action.VIEW");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
return true;
} else {
return false;
}
}
Related
I created a WebView App and it's working fine but there is a link which I want it to open in the default browser instead of that app what can I do.
Add a WebViewClient to your webView (if not already added) and then override shouldOverrideUrlLoading () method:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
if (url.contains(myUrl)) {
Intent intent= new Intent(Intent.ACTION_VIEW, myUrl);
context.startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(webview, url);
}
}
}
This way your are telling your webview to not continue loading a specific url. Instead, launch the proper application (mostly a browser) to handle the url.
I have a webview where I perfectly load a google form. In the google form there is a link that redirect to a web page, something like "https://www.google.com/url?q=http://www.mywebsite.com/support/" but no matter what I do I cannot open this link. Everything else work fine.
WebSettings webSettings = supportWebPageWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
supportWebPageWebView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
//do stuff
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
//do stuff
}
});
The only way to make it work is open the link in a browser.
Anyone had the same problem?
I haven't noticed that clicking on the link it opens a new window, the answer is than here Android - Open target _blank links in WebView with external browser
I'm currently developing an application with android WebView.
However, the website has a link that will invoke Skype application.
The link work fine when try with Chrome browser on android, but it return an error when try to open in android WebView. Actually, it gave me an Webpage not Available error.
Any advice?
Regards.
You should check the url that is click/opened in the webview and check if there is an application that handles this kind of urls:
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == skype url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
} else {
view.loadUrl(url);
}
return true;
}
});
I need to implement component that shows list of pictures related to given search query. Pictures are loading from google picture search.
What can I use instead of google picture search?
Parse json from
https://developers.google.com/image-search/?hl=ru (deprecated and limited)
https://developers.google.com/custom-search/docs/overview (free but with limitations)
Run search query in hidden WebView and get list
of images after page loading.
enter code here
query = "https://www.google.com.ua/search?safe=on&site=imghp&tbm=isch&q=milk+buy";
web = (WebView) v.findViewById(R.id.web);
web.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
}
// you tell the webclient you want to catch when a url is about to
// load
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
// here you get all links to pictures
#Override
public void onLoadResource(WebView view, String url) {
Log.i("web link", String.format(url));
if (url.compareTo(query) != 0) {
images.add(url);
}
}
});
web.loadUrl(query);
Check out this example on Github:
https://github.com/koush/ion/blob/master/ion-sample/src/com/koushikdutta/ion/sample/GoogleImageSearch.java
I have a WebView in which I load a page with a custom link (like app://action). I registered the url schemes in the manifest file and when I click on the link, the onResume() method of my Activity is called with the correct data and it works OK.
My problem is that the WebView still try to load the link and my WebView ends up to show a "Web page unavailable" message. I don't want that.
How can I prevent the WebView to load the url?
Here's my code :
WebView banner = ...
banner.setWebViewClient(new WebViewClient() {
#Override
public void onLoadResource(WebView view, String url) {
if (url.startsWith("app://")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url), getContext(), Main.class);
//startActivity(i);
}
}
}
banner.loadUrl("url_to_the_banner");
Use WebViewClient.shouldOverrideUrlLoading instead.
public boolean shouldOverrideUrlLoading(WebView view, String url){
// handle by yourself
return true;
}
WebViewClient Reference
Updates: Method shouldOverrideUrlLoading(WebView, String) is deprecated in API level 24. Use shouldOverrideUrlLoading(WebView, WebResourceRequest) instead.
But it must return false otherwise, so:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.startsWith(myString){
// handle by yourself
return true;
}
// ...
return false;
}