Gps 以编程方式在Android设备中安装“谷歌游戏服务”

Gps 以编程方式在Android设备中安装“谷歌游戏服务”,gps,google-play-services,android-location,Gps,Google Play Services,Android Location,在我的设备(Karbon A 21移动电话)中,当未安装Google Play Services时,我的location对象为null,当Google Play Services安装时,它返回正确的位置 我知道我可以检查googleplay服务是否使用-GooglePlayServicesUtil安装。googleplayservicesavaailable(this)。 但我可以实际安装googleplayservices,还是让用户手动安装 为什么其他应用程序显示位置,即使未安装google

在我的设备(Karbon A 21移动电话)中,当未安装
Google Play Services
时,我的
location
对象为
null
,当
Google Play Services
安装时,它返回正确的位置

我知道我可以检查
googleplay服务
是否使用-
GooglePlayServicesUtil安装。googleplayservicesavaailable(this)
。 但我可以实际安装
googleplayservices
,还是让用户手动安装

为什么其他应用程序显示位置,即使未安装
googleplay服务
? 我的代码中是否有错误。请参阅下面的代码

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  Criteria criteria = new Criteria();
  criteria.setCostAllowed(true);
  provider = locationManager.getBestProvider(criteria, true);
  Location location = locationManager.getLastKnownLocation(provider);

这就是我要做的。如果谷歌Play服务不可用,它会要求用户安装谷歌Play服务,或者要求用户安装谷歌地图的当前版本

如果您使用的是API19,那么您需要在清单中包含以下内容

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

我在安装
谷歌游戏服务时也遇到了同样的问题。
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />