Detecting GPS on/off switch in Android phones

后端 未结 4 898
心在旅途
心在旅途 2020-11-30 01:20

I would like to detect when the user changes the GPS settings on or off for an Android phone. Meaning when user switches GPS sattelite on/off or detection via access points

4条回答
  •  情深已故
    2020-11-30 01:58

    Try this,

    try {
            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    
                Log.i("About GPS", "GPS is Enabled in your devide");
            } else {
                //showAlert
            }
    

提交回复
热议问题