How to Set flight mode and call system programs in Android programming-[Android Development]

Source: Internet
Author: User
One Android app Program It is mainly to set the scene mode on a regular basis, so we need to call the flight mode through programming. After searching, we cannot find the relevant explanations and descriptions, finally, I saw a solution on a foreign forum and finally solved the problem. Code As follows: 1 // Skip row Mode
2 Protected Void Offline ( Boolean Setairplane ) {
3 Settings . System . Putint ( Getcontentresolver (),
4 Settings . System . Airplane_mode_on , Setairplane ? 1 : 0 );
5 Intent Intent = New Intent ( Intent . Action_airplane_mode_changed );
6 Intent . Putextra ( "Testcode" , "Ellic" );
7 Sendbroadcast ( Intent );
8
9 }

We can use airplanemodeon = settings. system. getint (mcontext. getcontentresolver (), settings. system. airplane_mode_on, 0) = 1? True: false; to determine whether the phone is in flight mode.

Next, we will analyze how to call the system program in Android programming. the most convenient way to call the system program is to activate it directly through intent. Intent is really a good thing. If you are free, you have to worry about it. Here are several examples:
1. Call the system email program

    • Final intent emailintent = new intent (Android. content. Intent. action_send); // create an intent object
    • Emailintent. settype ("plain/text"); // sets the text format
    • Emailintent. putextra (Android. content. Intent. extra_email, new string [] {}); // you can specify the recipient's email address.
    • Emailintent. putextra (Android. content. Intent. extra_subject, "Hello World !"); // Set the title content
    • Emailintent. putextra (Android. content. Intent. extra_text, "It is body-Hello world !"); // Set the mail text content
    • Startactivity (intent. createchooser (emailintent, "sending mail ...")); // Start a new activity

2. Call the system SMS Program

    • Uri uri = URI. parse ("smsto: 0800000123 ");
    • Intent it = new intent (intent. action_sendto, Uri );
    • It. putextra ("sms_body", "the SMS text ");
    • Startactivity (it );

3. When calling the system alarm program, it must be noted that the calling of the system alarm program should be noted that different sdks and classname are different, and the Android devices produced by different manufacturers may be different, in Motorola's defy, The classname of the alarm is com. motorola. blur. alarmclock instead of COM. android. alarmclock. alarmclock, so we need to modify this method accordingly: public intent setclassname (string packagename, string classname ).

    • Intent intent = new intent ();
    • Intent. setclassname ("com. Android. alarmclock", "com. Android. alarmclock. alarmclock ");
    • Startactivity (intent );

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.