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

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

问题描述

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

,即使启用GPS,它也会返回false。全球定位系统工作正常,但我使用这个布尔值显示弹出没有GPS启用。在这种情况下,每次弹出窗口都会显示出来。


  1. 我检查了类似的问题,但它对我没有帮助。 b $ b
  2. 是的,我在清单中拥有许可权

  3. 我在onResume方法中使用此代码

感谢您的帮助。

解决方案

试试这种方法..

  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);
}
}


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天全站免登陆