Toggle Android Airplan mode

This code show to Toggle Airplane mode of mobile
public void airplaneModeOn( ) {
        try {
            boolean isEnabled =  Settings.System.getInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
            Settings.System.putInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON, isEnabled    ? 0 : 1);
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", !isEnabled);
            sendBroadcast(intent);
            Toast.makeText(this, "Mode is "+!isEnabled  , Toast.LENGTH_LONG).show();
        } catch (Exception e) {

            Toast.makeText(this, "exception:" + e.toString(), Toast.LENGTH_LONG).show();
        }
   }

Called this method from button click event to Toggle Airplane mode.

Comments

Popular posts from this blog

Thread in Android

Android Age Calculator

How to Open Multiple apps in mobile it same time: multitasking feature in mobile