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.
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...
}
}
});
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
I have a sharepoint site, which has ntlm authentication. in order for me to load the page, i do an authentication to the site using this.
public String LoadUrlWithNTLM(String url){
CkHttp http = new CkHttp();
http.put_Login("username");
http.put_Password("password");
http.put_NtlmAuth(true);
http.put_SessionLogFilename("ntlmAuthLog.txt");
String source = http.quickGetStr(url);
return source;
}
and load the webview with this.
public void LoadWebView(String url, String source){
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadDataWithBaseURL(url, source, "text/html", "", "");
}
i call this in the OnCreate()
source= LoadUrlWithNTLM(url);
LoadWebView(url,source);
then i check if there is a url event click with this
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
String toWebView = LoadUrlWithNTLM(url);
LoadWebView(url,source);
return false;
}
});
at some point, i can manage through go to the Sharepoint Site with NTLM Authentication, but when i click some link, it just display "401 UNAUTHORIZED" and do not invoke the shouldOverrideUrlLoading() method on breakpoint.
After authorizing, each subsequent HTTP request should include an Authorization header that contains the result of the prior authorization. If the subsequent request were sent using Chilkat HTTP, then the object would automatically send this Authorization header. However, the WebView has no knowledge of it, and it's including any Authorization header with it's request, and therefore you get the "401 Unauthorized" error.
One solution is to see if you can do NTLM authorization with WebView. I'm assuming you're using Chilkat only because this is not possible.
Another solution is to use Chilkat as you are doing, but then get the value of the Authorization header (from Chilkat) and explicitly set this header field with WebView. I don't know enough about WebView to know whether this is possible. To get the value of the Authorization header from Chilkat may require a new Chilkat feature (and I think this may be easy to do). (or it's already possible, but in a convoluted way)
I have a webview in Android app and load my webapplication. I am listening the page navigation using ShouldOverrideURL method and do some operation. I want to do specific operation when the URL method type is GET or POST. I cannot use PostURL method here as I load only one home URL.
It looks like shouldOverrideUrl is only called during GET requests: Android - how to intercept a form POST in android WebViewClient on API level 4
If you want to do a specific operation during a POST operation for a particular URL, you want to extend WebView and override WebView#postUrl(String url, byte[] postData).
Now i try to Implement Twitter Integration in android using twitter4j library.Few months back I successfully implemented this using a dummy call back url like "PicPuzzle://tkxel".
But now Twitter changes its scheme and now not allow to create application with dummy URL.
Now the problem is after authentication It redirect to callbackurl But not return to application.
I specify the same url in application and registration page. I refered Problem in Callback in Twitter in Android and How I can call back in Android using OAuth for Twitter?. But these solutions are now not working because now twitter not allow to create application with dummy URL. Please help me to solve this problem.
Follow below steps:
Go to Twitter Apps: https://apps.twitter.com/
Then, Go to your app.
Go to Settings Tab
In section "Callback URLs", add the below line:
twittersdk://
Click button "Update Settings" at the bottom. That's it.
Hope this works!
Create your own WebViewClient subclass.
Override shouldOverrideUrlLoading(WebView view, String url) method.
In shouldOverrideUrlLoading(), check if url.startsWith(YOUR_CALLBACK_URL) is true.
If true, retrieve "oauth_verifier" parameter from the URL and return true (true from shouldOverrideUrlLoading() prevents the WebView instance from loading the URL).
Get an access token using the value of the parameter obtained in the step 4.
Your application can get control back from the WebView instance after the step 4.
If the above steps sound cumbersome, try TwitterOAuthView. Its usage is very simple. Just call
view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener);
and receive the result via TwitterOAuthView.Listener interface defined as below.
void onSuccess(TwitterOAuthView view, AccessToken accessToken);
void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result);
If true is given to TwitterOAuthView.start() method as the forth argument, TwitterOAuthView does not access the callback URL, and I think this behavior is what you want to implement. The source code, TwitterOAuthView.java, may be of help.