Android code operation gps Switch

Source: Internet
Author: User

When studying android gps, I found that the android system hides the interface for gps switch operations, and I don't know why, I personally think it may be because all the programs are operating on the gps switch, leading to confusion! However, I still saw a method to operate on the gps switch using code on the Internet. Contribute!

========================================================== ========================================================== ====

Directly run the Code:


Private voidtoggleGPS (){

IntentgpsIntent = newIntent ();

GpsIntent. setClassName ("com. android. settings ",

"Com. android. settings. widget. SettingsAppWidgetProvider ");

GpsIntent. addCategory ("android. intent. category. ALTERNATIVE ");

GpsIntent. setData (Uri. parse ("custom: 3 "));

Try {

PendingIntent. getBroadcast (this, 0, gpsIntent, 0). send ();

}

Catch (CanceledExceptione ){

E. printStackTrace ();

}

}


From chenghai2011

Related Article

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.