Android 谷歌定位服务Vs安卓定位服务

Android 谷歌定位服务Vs安卓定位服务,android,android-location,Android,Android Location,正如我们所知,我们有两种备选方案,用于使我们的应用程序位置感知 我们要么使用谷歌的定位服务API(谷歌Play服务的一部分),要么使用Androids定位API 我这里的问题是,使用谷歌的服务,我们必须使用接口com.Google.android.gms.location.LocationListener来为我们提供位置更新。 然而,与android.location.LocationListener不同的是,谷歌的版本并没有向我们提供位置提供商(gps或互联网)的状态 我们在Androids位

正如我们所知,我们有两种备选方案,用于使我们的应用程序位置感知 我们要么使用谷歌的定位服务API(谷歌Play服务的一部分),要么使用Androids定位API

我这里的问题是,使用谷歌的服务,我们必须使用接口com.Google.android.gms.location.LocationListener来为我们提供位置更新。 然而,与android.location.LocationListener不同的是,谷歌的版本并没有向我们提供位置提供商(gps或互联网)的状态

我们在Androids位置侦听器中有以下方法

abstract void   onLocationChanged(Location location)
Called when the location has changed.
abstract void   onProviderDisabled(String provider)
Called when the provider is disabled by the user.
abstract void   onProviderEnabled(String provider)
Called when the provider is enabled by the user.
abstract void   onStatusChanged(String provider, int status, Bundle extras)
Called when the provider status changes

然而,在谷歌,我们只有一个

abstract void   onLocationChanged(Location location)
如果我使用谷歌服务,我将如何识别提供商的变化。例如,在应用程序使用过程中,用户决定关闭GPS,我想为这个事件干杯

我不知道该怎么做

谷歌的版本没有向我们提供位置提供商(gps或互联网)的状态

在某种程度上,这是因为它没有使用任何单一的位置提供程序

如果我使用谷歌服务,我将如何识别提供商的变化


您可以尝试监听。

您注册了一个接收器来处理已更改的活动提供程序

private static final String ACTION_GPS = "android.location.PROVIDERS_CHANGED";
private BroadcastReceiver yourReceiver;

private void checkGPS() {
    Context context = this.getApplicationContext();
    if (context != null) {
        Button btnGPS = (Button) findViewById(R.id.btnGPS);
        if (btnGPS != null) {
            LocationManager locationManager = (LocationManager) context
                    .getSystemService(Context.LOCATION_SERVICE);
            boolean b = locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
            locationManager = null;
            if (b) {
                if (btnGPS.getVisibility() != View.GONE) {
                    btnGPS.setVisibility(View.GONE);
                }
            } else {
                if (btnGPS.getVisibility() != View.VISIBLE) {
                    btnGPS.setVisibility(View.VISIBLE);
                }
            }
        }
    }
}

private void registerReceiverGPS() {
    if (yourReceiver == null) {
        // INTENT FILTER FOR GPS MONITORING
        final IntentFilter theFilter = new IntentFilter();
        theFilter.addAction(ACTION_GPS);
        yourReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null) {
                    String s = intent.getAction();
                    if (s != null) {
                        if (s.equals(ACTION_GPS)) {
                            checkGPS();
                        }
                    }
                }
            }
        };
        registerReceiver(yourReceiver, theFilter);
    }
}


 @Override
 public void onResume() {
 super.onResume();
 checkGPS();
 registerReceiverGPS();



    @Override
public void onStop() {
    super.onStop();
    // Do not forget to unregister the receiver!!!
    if (yourReceiver != null) {
        unregisterReceiver(yourReceiver);
        yourReceiver = null;
    }

勾选此项,您是否可以建议任何机制,通过该机制,我可以通知用户他忘记从设置中打开位置传感器。我想这要求并不过分。这种情况可能会发生很多次。用户将等待位置更新未知的事实,即他忘记打开适配器。@MuhammadAhmedAbuTalib:“那么,您能建议任何机制,通过它我可以通知用户他忘记从设置打开位置传感器吗?”--使用
LocationManager
isProviderEnabled()
。仅仅因为您通过
LocationClient
获取位置,并不意味着您被禁止使用
LocationManager
进行其他操作。而且,仅仅因为
LocationClient
提供了位置,并不意味着
LocationClient
必须完全复制
LocationManager
API的其余部分。