GPS 开启和关闭

//4.0.4 验证成功 GPS turn off

public void turnGPSOff()

{

 

//4.0.4 验证成功

Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); 

intent.putExtra("enabled", false); 

sendBroadcast(intent);

}

 

public void turnGPSOn()

{

    Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");

    intent.putExtra("enabled", true);

    this.sendBroadcast(intent);

 

   String provider = Settings.Secure.getString(mContext.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);

 

 

   }

}

你可能感兴趣的:(gps)