Android sets the flight mode to determine whether it is a flight mode

Source: Internet
Author: User

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

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.