Display a dialog box with an error Google Play Services is not installed and redirect the user to it

Hello, I'm trying to use the GCM application in android, where I need to check whether the use of Google Play Service installed or not. For this, I encoded, but I can’t cope with a situation where the user does not have Google Play Service .

Is there any built-in way to give the operator the ability to install the Google Play Service and redirect it to play to install it.

 /** * Check the device to make sure it has the Google Play Services APK. If * it doesn't, display a dialog that allows users to download the APK from * the Google Play Store or enable it in the device system settings. */ public static boolean checkPlayServices(Context mContext) { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, (Activity)mContext,Constants.PLAY_SERVICES_RESOLUTION_REQUEST).show(); } return false; } return true; } 

// check here if the Google Play device is installed. // if it is installed, then register the device using GCM // otherwise redirect the user to play in the store to install it.

  if(Utils.checkPlayServices(getActivity())) { new RegisterGCMDeviceAsynTask(new TaskCompleteListener() { @Override public void onTaskCompleted(String result) { new TeemWurkAsyncTask(new TaskCompleteListener() { @Override public void onTaskCompleted(String result) { Logger.d(TAG, result); } }, Constants.LOGIN_API_CALL).execute(""); } }).execute(); } else { // display the dialog that device do not have Google Play Service installed. } 
+6
source share
1 answer

Something like that:

 if(!isGooglePlayServicesAvailable()) { GooglePlayServicesUtil.getErrorDialog(999999999, this, RQS_GooglePlayServices).show(); } 

999999999 - The request code (random integer) used in onActivityResult() .

+5
source

Source: https://habr.com/ru/post/969948/


All Articles