Getting SLL certification information on Android webview - android

I am using webview in my app. when the user browses to a https site, how do I get the certificate information for the site/page that just finished loading.
Just like how when you click on the green lock icon on chrome browser and it pops up a dialog with certificate information, how do I get it from webview?
Thank you

Answering my own question, dont know how I missed this!!!!
#Override
public void onPageFinished(WebView view, String url)
{
Log.e(view.getCertificate().toString());
}

Related

Android with webview with remote website

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

How to prevent the user from going to the apps and continue with browser

In my mobile site I have links to other websites that also have apps. when my users click on the links they get options in Android (I don't know about iPhone) to go to the app or continue with the browser. How do I prevent the user from going to the apps and just cntinue with the browser after clicking my links without seeing this menu (browser/app)?
What you're asking is how to prevent the expected behavior of a webpage you load in your app. That's generally not good UI/UX design. But, to do so you would need to set a WebViewClient on your WebView and evaluate the url that is being loaded to see if it is for the download of an app:
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (url.contains("play.google.com")) {
//handle alternate action here
}
}
#Override
public void onPageFinished(WebView view, String url){
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
That's something that's been set up on the 3rd party site, not something that's being done by the OS. There's no way to control the behavior of the browser after the user has left your web site.
For example LinkedIn will do this but Last Pass does not, even though they also have an app. This is something LinkedIn has chosen to do with their site; you can't do anything about that from your web site.

Open URL with custom BROWSER

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

Flickr-Android API : Oauth is not redirecting to 'grant-access' page

I'm developing an Android application which requires Flickr API integration. In previous days, I was able to successfully complete the oauth process. But now its not working, and I strongly believe it happend after flickr APIs changed from http:// to https://
Let me explain the situation..
I'm following the steps explained in Flickr API Doc
As a result of the call to http://www.flickr.com/services/oauth/request_token API, I'm successfully receiving the oauth_token.
After this step, I'm presenting Flickr authorization page in a webview with the url specified in API doc (which is somthing similar like, https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432, and of-course, with the oauth_token which I received in the previous step)
Few days before this call was working when I'm using http:// instead of https://. But now, both http:// and https:// are not working. The page is displaying the login screen, but after successful login, the page is not redirecting to the grant access page, instead it is just redirecting to the Flickr Home page. And hence, I'm unable to grant access and unable to receive the oauth_verifier.
Hope I'm well explaining the situation which I'm facing now. But in short, Flickr Login for my application is not working, and I'm running out of time... :(
So, Geeks, Please give some light on the issue...
--Thanks in advance.
I got the same problem. I was using the connection in a WebView and my code was using the "http" protocol in the request.
I could resolve the issue by first using the "https" protocol for the authentification URL. As you say just doing that did not work. So I change the call of the url that was in the WebView and used the ACTION_VIEW intent and it worked.
Calling :
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(AuthentificationPath)));
Don't forget to implement the OnResume() function of your Activity to get the data of the returned intent.
Of course it is just a workaround but it does the job if you have to be fast.
Hope it helps!
Still the issue is there, After oauth Flickr is not redirecting to grant_access page. But I need to get the oauth process successfully completed in my on-going project, as soon as possible. So I have done a workaround to solve the issue.
To solve the 'not redirecting' issue, I have done a little bit change in my WebView's WebViewClient implementation. It's nothing great, but just redirecting to authorize page again, after successful login.
Authorize URL Example : https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432
So, given below is the detailed implementation of WebViewClient:
mAuthWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showProgressDialog();
/** TODO: This part should be deleted after flickr fixes the oauth redirection issue */
if(url.endsWith("flickr.com/")) {
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
return;
}
/* After successful login the redirected url will contain a parameter named 'oauth_verifier' */
if (url.indexOf("oauth_verifier=") > -1) {
/* Get the 'oauth_verifier' parameter from url and do next steps */
performLoginSuccess();
}
}
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains(_my_redirect_url_) && !url.contains("oauth_verifier=")) {
/* User not authenticated our app */
finish();
} else if (!url.contains("oauth_verifier=")) {
killProgressDialog();
}
}
});
After loading the authorization url, the web view will take the user to login page, and after user successfully loged into Flickr, with web vew client implementation we are again loading the authorization url, to present the grant access page.
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
I know, this is not the right way to do this...
Any better solutions are always welcome.... :)

android: delete history after homepage load

hey, an android noob needs help here.
i'm trying to get my webview browser to delete the browser history after the homepage has been loaded (so the next user that comes around this public app doesn't see the previous session)
i've made a webview client and put a
public void onPageFinished(WebView webView, String Url ) {
Browser.clearHistory();
but don't know how to change the String Url to the url of the apps homepage.
I also tried adding a second function to my homebutton onclicklistener, but no luck as well, if someone wants to help i can paste that bit of code as well.
thanks
Here how I did;
#Override
public void onPageFinished(WebView view, String url) {
junc.pg.setVisibility(View.INVISIBLE);
if(url.indexOf("a_string_unique_to_your_homepage")!=-1) {
view.clearHistory();
}
}
Here, you can define a unique string for your url. For example if your homepage url is
www.example.com
you can call it with
www.example.com?12345abc
and search for this unique number 12345abc.
It works, I have tested several times.
Sorry Matt you canĀ“t delete your Browser history programatically in Android.
you will achieve that manually
Browser ..> Settings > Clear History > OK
What about?
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());

Categories

Resources