In my app, i am loading "http" url in the webview. This url is loaded correctly, but there are some internal url's loaded with the protocol "sheet://". While loading this url i get an error "protocol isn't supported". Can anyone please help how to fix this? How to load the url's with the protocol "sheet://" ?
PS: I am using shouldOverrideUrlLoading method to load the url.
This is the code I am using
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("sheet://")){
Intent url_intent = new Intent ( Intent.ACTION_VIEW,Uri.parse(url));
url_intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(url_intent);
return false;
}else{
view.loadUrl(url);
return true;
}
}
Thanks & Regards,
Perhaps host an PHP file, with an header?
<?php
header("Location: sheet://link_to_your_file.extention");
?>
Do you see the call to shouldOverrideUrlLoading come in for your sheet:// URL? That part of the code looks correct (assuming there is an app installed on your device that can handle sheet:// BROWSABLE intents). Or do you mean that the app launched from your app cannot load the sheet:// URL? What app is being launched to respond to the Intent?
One mistake you have is the call to loadUrl when sheet:// is not in the URL. In this case, please just return true. The URL load is already in progress, there is no need to start it again. Doing so infact creates a loop.
You have to register an activity with an intent-filter that matches that protocol in your AndroidManifest.xml
Related
My android app has a webview which directly goes to the remote PHP site and shows user the registration form.
My question is, once user get registered successfully I want to close the webview and start another activity which is in native view. But how can I know whether he/she got registered successfully or not?
Thanks
You can do it this way:
In your PHP code, when the user gets registered successfully, redirect user to a unique link(this link will be used in your android code). Let's assume the link you redirect user to is "https://blablabla.com/successfully_registered"
In the WebViewClient's OnPageStarted method used by your WebView, Get the URL and check if it's similar to your redirect URL we assumed you used in your PHP code.
For Example:
WebView wv = findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
//check if URL is similar to redirect URL
if(url.contains("https://blablabla.com/successfully_registered")){
view.stopLoading();
//user have been successfully registered. Start another activity or do something else...
}
}
});
I have a hybrid application where I have a WebView which is implementing the shouldOverrideUrlLoading method (both the deprecated and the newest version). This should take over control before loading any external links or certain links within my domain. Without going into specifics, the code looks roughtly like this:
private WebView mWebView;
mWebView.setWebViewClient(new myWebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.isExternal() || url.contains("#specialCase")) {
// Do actions
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
I have noticed that all external links work properly, however shouldOverrideUrlLoading is not being called at all when the link is within my domain, so there is no way for me to detect those cases where I want to take over control.
The android documentation states
Give the host application a chance to take over the control when a new
url is about to be loaded in the current WebView.
Does that new mean different domain? Is there anything I am missing or doing wrong? Any ideas on how to detect the user has clicked a link pointing to the same domain?
Thank you in advance.
Finally found the reason why shouldOverrideUrlLoading was never been called.
Apparently the method is only called when the actual loading is about to start. Our web application is a single-page application, hence even though the URL changes, no new page is loaded and shouldOverrideUrlLoading is not called.
Good day!
Guys, I have a problem and want your help.
Through a WebView, how do I get when clicked by the user, do not open the options of standard browsers (eg chrome and internet). I saw an app by clicking the link to the page opens normally however, as if open in a custom browser. I found it very interesting, and I wonder how this mechanics.
If anyone know how to create an app that perform the same procedure I am grateful.
For better doubt the APP is this:
https://play.google.com/store/apps/details?id=com.tachanfil.jornaisdobrasil&hl=pt-BR
You have to set up WebViewClient like
this.mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
Then your app will display all links in your WebView instead of opening browser
Perhaps you are missing setting your client as the webview client - Refer to
http://developer.android.com/reference/android/webkit/WebView.html#setWebViewClient%28android.webkit.WebViewClient%29
I am developing an app that is similar to a web browser.
Now when i click on an email address in a web page displayed thru a WebView, this is what happens :
A set of email clients for me to choose from are displayed
The webview tries to load the url, "mailto:abc#xyz.com" and displays the error page when it cannot find the url.
I am trying to figure out how to solve the problem in No.2.
Basically, i do not need the app to load the url that contains a 'mailto:'.
Here's what i have tried to do but failed:
under 'shouldOverrideUrlLoading()',
if( url.startsWith("mailto") )
{
/*Do the stuff for sending email but i will not display */
url = null;
}
Before the view.loadurl(url),
Added a
if( !url.startsWith("mailto:") )
view.loadurl(url);
I know these are hacks and are not very elegant.
Hence, can someone point me in the right path ?
Thank you.
Try with using return true; in shouldOverrideUrlLoading() method. :)
Ravi Bhatt's answer is correct. At the end of the function, it should return true;
BUT you will have to manually capture any url containing http or https and load the url. Here's what i meant :
Under shouldOverrideUrlLoading(),
else if( url.startsWith("http:") || url.startsWith("https:") )
{
view.loadUrl(url); //u can use the default webview or your own webview
}
/*At the end of the function*/
return true;
If you put in a return false somewhere, it will not work too.
url = null will not help too.
Hope this helps anyone else out there with similar problems to mine.
Stuck on an issue with http post data.
So we've created a webview to work in.
Then called a third party webservice this ask's to provide a postback url and some parameters, the webservice then processes the paramaters and redirects the user (our app) to the postback url we provided, with some data as a http post.
We want to get the post data from this postback url but within the webview or within our app.
Tried intercepting the url load with this code:
final WebView webview = new WebView(this);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Grab data here...
return super.shouldOverrideUrlLoading(view, url);
}
});
However can't seem to find any objects or methods to gain access to the data within this method.
The other attempt was to give them the postback url as an intent within our app like:
myscheme://someText/someParam
this would have started a new activity when the postback is called (as we have set up an intent-filter within our android-manifest), this intent fires up our app activity within a browser but not within our webview, but anyway again we can't see how to access the post data from this.
Thanks for looking,
Any ideas?
Didn't find a way to do this. Basically can't get at data posted at a webview or a browser intent.
Instead the solution we went with is:
Postback to a server, get the postdata here (PHP) and save in a DB, then retrieve the data from this DB within the phone.