如何找出android设备的gps是否已启用?在一个启用Android Cup蛋糕(1.5)的设备上,我如何检查和激活GPS?
3 回答
慕娘9325324
TA贡献1783条经验 获得超5个赞
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null){
Log.v(TAG, " Location providers: "+provider);
//Start searching for location and update the location text when update available
startFetchingLocation();
}else{
// Notify users and show settings if they want to enable GPS
}Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);startActivityForResult(intent, REQUEST_CODE);
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == REQUEST_CODE && resultCode == 0){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null){
Log.v(TAG, " Location providers: "+provider);
//Start searching for location and update the location text when update available. // Do whatever you want
startFetchingLocation();
}else{
//Users did not switch on the GPS
}
}
}- 3 回答
- 0 关注
- 617 浏览
添加回答
举报
0/150
提交
取消
