gps - Programatically install `Google Play Services` in Android device -


in device( karbon 21 mobile phone) , when google play services not installed, location object null , while google play services installed, returns correct location.

i know can check if google play services installed using-googleplayservicesutil.isgoogleplayservicesavailable(this). can install google play services pragmatically or should ask user install manually?

why other app shows location if google play services not installed? doing wrong in 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); 

here do. asks user install google play services if not available, or 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 using api19, need following in manifest.

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