我需要检查我onReceive()
的{{1}}方法中是否启用了位置设置,以获取位置更新并使用该位置继续进行。我知道如何使用BroadcastReceiver
或LocationManager
从活动中执行此操作,但如何从SettingsApi
执行此操作?
答案 0 :(得分:0)
您可以按如下方式检查位置服务:
LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
boolean gps_enabled = false;
boolean network_enabled = false;
try {
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch(Exception ex) {}
try {
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex) {}
if(gps_enabled || network_enabled ){
//Do something.
}