Android Settings GPS Auto-Open

Source: Internet
Author: User

1. The first method

Private voidTogglegps () {Intent gpsintent=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 (startactivity). This,0, Gpsintent,0). Send (); } Catch(canceledexception e) {e.printstacktrace (); }    } 

2. The second method

   Private voidopengpssettings () {//Get GPS status now (open or closed)Boolean gpsenabled =Settings.Secure.isLocationProviderEnabled (Getcontentresolver (), locationmanager.gps_provider); if(gpsenabled) {//Turn off GPSSettings.Secure.setLocationProviderEnabled (Getcontentresolver (), Locationmanager.gps_provider,false ); }    Else    {     //Turn on GPSSettings.Secure.setLocationProviderEnabled (Getcontentresolver (), Locationmanager.gps_provider,true); }

3. Third method (manual setting)

Locationmanager alm = (locationmanager) startactivity. This. Getsystemservice (Context.location_service); if(alm.isproviderenabled (Android.location.LocationManager.GPS_PROVIDER)) {Toast.maketext ( This,"GPS Module Normal", Toast.length_short). Show (); } toast.maketext ( This,"Please open gps! ", Toast.length_short). Show (); Intent Intent=NewIntent (settings.action_security_settings); Startactivityforresult (Intent,0);//This is the return to the Get interface after Setup is complete    

The first and second kind need to add permission

<!--allows programs to read or write system settings--<uses-permission android:name="Android.permission.WRITE_SETTINGS " ></uses-permission> <uses-permission android:name="android.permission.WRITE_ Secure_settings"/>

Description

The first: Some of the phones are invalid
The second type: since Level8
The third type: it is commonly used in this

http://blog.csdn.net/beihai1212/article/details/7692317

Android Settings GPS Auto-Open

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.