android 强制开启 GPS

4.0后强制开启GPS代码:

public void turnGPSOn() 

    Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); 
    intent.putExtra("enabled", true); 
    this.sendBroadcast(intent); 
 
   String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); 
   if(!provider.contains("gps")){ //if gps is disabled  
       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"));  
       this.sendBroadcast(poke); 
   } 

你可能感兴趣的:(android,s)