The advantages of the flight mode are:
1. You can have a quiet rest time
2. Reduce radiation to the body
3. Saving Power
4. Do not close the alarm
Therefore, it is very useful to set the flight mode.
The following is an example:
Set the required permissions for the flight mode in the Code:
[Html]
<Uses-permission android: name = "android. permission. WRITE_SETTINGS"/>
Implementation Code:
[Java]
/**
* Set the mobile phone flight mode
* @ Param context
* @ Param enabling true: Set to flight mode; false: Cancel flight mode.
*/
Public static void setAirplaneModeOn (Context context, boolean enabling ){
Settings. System. putInt (context. getContentResolver (),
Settings. System. AIRPLANE_MODE_ON, enabling? 1: 0 );
Intent intent = new Intent (Intent. ACTION_AIRPLANE_MODE_CHANGED );
Intent. putExtra ("state", enabling );
Context. sendBroadcast (intent );
}
/**
* Determine whether the mobile phone is in flight mode
* @ Param context
* @ Return
*/
Public static boolean getAirplaneMode (Context context ){
Int isAirplaneMode = Settings. System. getInt (context. getContentResolver (),
Settings. System. AIRPLANE_MODE_ON, 0 );
Return (isAirplaneMode = 1 )? True: false;
}