Just a work around to get the version comparision done.
public boolean onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (googlePlayServiceEnabled() && isWithSMSRetrieverSupportedPlayServiceVersion()){
//Good to go
return true;
}
else{
return false;
}
}
Checks if GooglePlay Service is Enabled and Displays proper error dialog on errors.
private boolean googlePlayServiceEnabled() {
try {
GoogleApiAvailability instance = GoogleApiAvailability.getInstance();
int responseCode = instance.isGooglePlayServicesAvailable(context);
switch (responseCode) {
case ConnectionResult.SUCCESS:
return true;
default:
Dialog errorDialog = instance.getErrorDialog(this, responseCode, 123);
errorDialog.setCancelable(false);
errorDialog.show();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
Implicitly gets the installed play services version and compares it with 10.2
private boolean isWithSMSRetrieverSupportedPlayServiceVersion() {
try {
PackageInfo pi = getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0);
if (pi == null)
return false;
if (pi.versionName == null || pi.versionName.isEmpty())
return false;
String playServicesVersion = pi.versionName;
return isPlayServicesVersionValidForSMSRetriever(playServicesVersion);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean isPlayServicesVersionValidForSMSRetriever(String v) {
try {
String index1 = v.substring(0, v.indexOf('.', 0));
int versionInt1 = Integer.parseInt(index1);
if (versionInt1 < 10)
return false;
else if (versionInt1 == 10) {
String index2 = v.substring(3, 4);
int versionInt2 = Integer.parseInt(index2);
if (versionInt2 < 2) {
return false;
} else {
return true;
}
} else
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}