GPS isProviderEnabled 总是返回 false [英] GPS isProviderEnabled always return false

查看:33
本文介绍了GPS isProviderEnabled 总是返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I've got this code

 lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
 boolean isGPS = lm.isProviderEnabled (LocationManager.GPS_PROVIDER);

and it always return false, even when GPS is enabled. GPS is working correctly but I'm using this boolean value to show pop-up "No GPS enabled". In this situation pop-up is showing up every time

  1. I checked similar questions but it doesn't help me.
  2. Yes, i have permission in my manifest
  3. I'm using this code in onResume method

Thanks for help.

解决方案

try this way..

private void turnGPSOn(){   
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);   
if(!provider.contains("gps")){      
    final Intent poke = new Intent();  
    poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");           
    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);   
    poke.setData(Uri.parse("3"));      
    sendBroadcast(poke);  
    } 
}  

这篇关于GPS isProviderEnabled 总是返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆