Programmatically install Google Play Services on an Android device

On my device (Carbon A 21 mobile phone), when Google Play Services not installed, my location object is null , and when installing Google Play Services it returns the correct location.

I know that I can check if Google Play Services installed using GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) . But then can I install Google Play Services pragmatically or should I ask the user to install it manually?

Why is another application showing the location even if Google Play Services not installed? I am doing something wrong in my code. See code below.

 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setCostAllowed(true); provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); 
+4
source share
1 answer

That's what I'm doing. He asks the user to install Google Play Services, if it is not available, or the current version (for Google Maps).

 final int RQS_GooglePlayServices = 1; // Check status of Google Play Services int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); // Check Google Play Service Available try { if (status != ConnectionResult.SUCCESS) { GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show(); } } catch (Exception e) { Log.e("Error: GooglePlayServiceUtil: ", "" + e); } 

If you are using API19, you will need the following in the manifest.

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
0
source

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


All Articles