Google Play Services Connection Error - android

How would you handle displaying a connection error message to the user when we can't connect via Google Play and is missing?
This has to be Froyo compatible.

Display an alert when you got message from Google Play as Connection Error as below:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Found some unknown Error. Please try again after some time.")
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();

Related

Android App is not approved with SSL Error Handler

I released a production Android app last month, but I had trouble with the SSL Error Handler.
I followed Stackoverfollow's and Google's tutorials, however Google doesn't still approve my app (note: this QA is not a duplicate).
https://support.google.com/faqs/answer/7071387
SSL Error Handler WebView Android
My code is implemented the following:
Any Fragment or Activity that uses WebViewClient, I've controlled SSL Error like this
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
LogI("onReceivedSslError: " + error.getCertificate());
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
AlertDialog alertDialog = builder.create();
String message;
switch (error.getPrimaryError()) {
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted.";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired.";
break;
case SslError.SSL_IDMISMATCH:
message = "The certificate Hostname mismatch.";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid.";
break;
case SslError.SSL_DATE_INVALID:
message = "The date of the certificate is invalid.";
break;
default:
message = "A generic error occurred.";
break;
}
message += " Do you want to continue anyway?";
alertDialog.setTitle("SSL Certificate Error");
alertDialog.setMessage(message);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", (dialog, which) -> handler.proceed());
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", (dialog, which) -> handler.cancel());
alertDialog.show();
}
So, Why is my app not approved? What should I do next?
Thank you for your advice!
Update 1:
I released my app in 2019 and updated it many times (there was no problem). But from 2021/5 I've got this problem.
May these errors are from old APKs, AABs version, remove/deactivate it before submitting new APKs, AABs
you have to call either handler.cancel(); (thats for your case) or super.onReceivedSslError(view, handler, error); straight inside onReceivedSslError. HERE you have some doc, in which:
The host application must call either SslErrorHandler#cancel or SslErrorHandler#proceed
and also
Application overrides of this method may display custom error pages or silently log issues, but it is strongly recommended to always call SslErrorHandler#cancel and never allow proceeding past errors.
without any of these calls some Google bot which checks apps may think, that you are disabling any SSL validation at all, which may be insecure for user
This is the code I used in my App and it was accepted. The only difference I am seeing is the try-catch block. My suggestion will be to try a simpler version on Play Store first, then update that with the specific type error message.
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
try{
final AlertDialog.Builder builder = new AlertDialog.Builder(PaymentActivity.this);
builder.setMessage(R.string.notification_error_ssl_cert_invalid);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}catch (Exception e){
e.printStackTrace();
}
}

Google play rejected app while uploaded new Version

Google play message:
This app uses software that contains security vulnerabilities for users or allows the collection of user data without proper disclosure.
Below is the list of issues and the corresponding APK versions that were detected in your recent submission. Please upgrade your app(s) as soon as possible and increment the version number of the upgraded APK.
Vulnerability APK Version(s)
SSL Error Handler
For more information about the SSL error handler, please see this Android Developers Help Center article.
22
I already updated webviewclient code
Here is my code:
myWebView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError
error) {
final AlertDialog.Builder builder = new AlertDialog.Builder
(MyActivity.this);
builder.setMessage(R.string.sslerror_msg);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
});
Please share solution if any one face this kind of problem. Thanks in advance.
After lots of finding I found a solution. If you got this type error or notification message from google play-store during uploading APK then follow the following steps to solved this issue.
Solution:
1. If you use webView & redirect a website then add this code in your WebViewClient
myWebView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError
error) {
final AlertDialog.Builder builder = new AlertDialog.Builder
(MyActivity.this);
builder.setMessage(R.string.sslerror_msg);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
});
You got this error by using any third party library like InMobi. For InMobi use latest SDK of InMobi. This issue will be resolved in latest SDK of InMobi.
Download InMobi SDK: http://www.inmobi.com/sdk/
For more information of InMobi follow this link: https://support.inmobi.com/monetize/integration/android/android-sdk-integration-guide/

Webview avoid security alert from google play upon implementation of onReceivedSslError

I am getting security alert from google play saying:
Your APK has been rejected for containing security vulnerabilities, which violates the Malicious Behavior policy. If you submitted an update, the previous version of your app is still live on Google Play.
If I remove onReceivedSslError (handler.proceed()), page won't open.
Is there anyway I can open page in webview and avoid security alert.
and my website to put in my app need http or https ? I'm using http://mywebsite...
If you use onReceivedSslError method, then please remove onReceivedSslError method and make new APK.
Change onReceivedSslError() to:
#Override
public void onReceivedSslError(WebView v, final SslErrorHandler handler, SslError er) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Problem with Security");
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
Hope this will help you.

How to create an AlertDialog before an sms text is sent?

I would like to know if it is possible to create an AlertDialog before a text message is sent from the default messaging app. I have looked at other people's questions on intercepting outgoing sms messages, however, those only seem to show how to read the message and not actually prevent it from being sent. I also do not want to create my own messaging app from scratch, so please do not suggest that. Thank you.
First of all create a new AlertDialog object like this
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Now lets say the SMS you want to send is triggered by the click of a button. Lets call it sendSMS. Inside the onClick method set the parameters of the AlertDialog object like this :
sendSMS.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
builder.setMessage("You are about to send an SMS! are you sure you want to send it?")
.setTitle("Warning!")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
//*******************************
//PUT HERE THE SMS SENDING CODE!!!
//*******************************
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
//closes the dialog; nothing interesting happens here
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
});
return true;
}
This displays an AlertDialog with the click of a button, warning the user that he/she is about to send an SMS. If he/she clicks yes then, the SMS code is triggered. If he/she clicks no nothing happens.

Check Facebook Login in Android

I have an application that uses the Facebook SDK for Android to login into my application. But I am having some problems in checking whether the user is already logged-in or not. After the login page, the main interface will be displayed to the user. What I want is that, if the user has logged-in in its past interaction with application, the next time the application is launched, no more login screen just the main interface. So at start-up my application should check whether a user is logged in or not. How will I do it?
I tried using mFacebook.isSessionValid(), but it's always returning a false.
You can try the following code :
if(mFacebook.isSessionValid()) {
onFacebookClick();
}
private void onFacebookClick() {
if (mFacebook.isSessionValid()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Delete current Facebook connection?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
fbLogout();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
facebook_btn.setText(getResources().getString(R.string.signinout));
}
});
final AlertDialog alert = builder.create();
alert.show();
} else {
facebook_btn.setText(getResources().getString(R.string.signin));
mFacebook.authorize(this, PERMISSIONS, -1,new FbLoginDialogListener());
}
}

Categories

Resources