本文介绍了onProviderEnabled不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关GPS与放大器之间切换;网络位置提供我只是想在这样的方式,来确定当一个供应商被禁止切换到另一个,但没有被调用我的onProviderEnabled

For switching between GPS & Network location provider i just tried in a way like this, to identify when a provider is disabled switch to another, but my onProviderEnabled is not getting invoked

public void onProviderDisabled(String provider) {
  Toast.makeText(TrackerService.this, "Disabled : " + provider, Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String provider) {
  Toast.makeText(TrackerService.this, "Enabled : " + provider, Toast.LENGTH_LONG).show();
}

感谢。

推荐答案

定义一个位置监听器类似如下:

Define a location listener like the following:

LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {

            }
            public void onProviderDisabled(String provider) {}
            public void onProviderEnabled(String provider) {}
            public void onStatusChanged(String provider, int status, Bundle extras) {}
        };

然后:

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
  lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
  lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

这篇关于onProviderEnabled不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:44