GPS isProviderEnabled always return false

后端 未结 6 1206
梦谈多话
梦谈多话 2021-01-11 11:16

I\'ve got this code

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


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 11:58

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

提交回复
热议问题