Whenever i try to turn on and turn off GPS automatically KITKAT fires java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE exception...
from the following answer from stack overflow,, Android device GPS on/off programatically
i came to know,
* For The security purpose Google developer has block above both methods which were previously working fine.
* Hence conclusion is that You can not programmatically start GPS On or Off.
This is the code part where exception is thrown,
/** Method for stop GPS **/
public synchronized void onPauseGPSListener() {
mLogger.log("Remove GPS Location Update");
//this Line throws the exception--------------------------------
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
sendBroadcast(intent);
if (locationclient != null && mlocListener != null) {
locationclient.removeLocationUpdates(mlocListener);
locationclient.disconnect();
locationclient=null;
mlocListener = null;
}
StoptimerForGPSRemoveListener();
if (mcalMgr.mServerReset == 0) {
timerForGPSStartListener();
}
}
/** Method for Start GPS **/
public synchronized void onStartGPSListener() {
mLogger.log("Start GPS Location Update");
if (mlocListener == null) {
mlocListener = new MyLocationListener();
}
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
StoptimerForGPSStartListener();
if (mcalMgr.mServerReset == 0) {
initGPSModule(mnFrequency, mfChangeDistance);
} else {
mlocListener = null;
Intent mintent = new Intent("android.location.GPS_ENABLED_CHANGE");
mintent.putExtra("enabled", false);
sendBroadcast(mintent);
}
}
this is Logcat stack trace,
11-20 11:19:26.317: E/AndroidRuntime(7773): Process: com.teclever.tracking, PID: 7773
11-20 11:19:26.317: E/AndroidRuntime(7773): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=7773, uid=10160
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.os.Parcel.readException(Parcel.java:1465)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.os.Parcel.readException(Parcel.java:1419)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2451)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1264)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
11-20 11:19:26.317: E/AndroidRuntime(7773): at com.teclever.tracking.LocationGetter.onPauseGPSListener(LocationGetter.java:601)
11-20 11:19:26.317: E/AndroidRuntime(7773): at com.teclever.tracking.LocationGetter$1.run(LocationGetter.java:706)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.os.Handler.handleCallback(Handler.java:808)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.os.Handler.dispatchMessage(Handler.java:103)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.os.Looper.loop(Looper.java:193)
11-20 11:19:26.317: E/AndroidRuntime(7773): at android.app.ActivityThread.main(ActivityThread.java:5312)
11-20 11:19:26.317: E/AndroidRuntime(7773): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 11:19:26.317: E/AndroidRuntime(7773): at java.lang.reflect.Method.invoke(Method.java:515)
11-20 11:19:26.317: E/AndroidRuntime(7773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
11-20 11:19:26.317: E/AndroidRuntime(7773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
11-20 11:19:26.317: E/AndroidRuntime(7773): at dalvik.system.NativeStart.main(Native Method)
11-20 11:19:27.026: E/(706): Could not open '/data/data/hotplug/cmd'
11-20 11:19:27.027: E/(706): error : 2, No such file or directory
11-20 11:19:27.104: E/(1015): appName=com.jrdcom.launcher, acAppName=/system/bin/surfaceflinger
11-20 11:19:27.104: E/(1015): 0
11-20 11:19:27.179: E/(706): Could not open '/data/data/hotplug/cmd'
11-20 11:19:27.180: E/(706): error : 2, No such file or directory
11-20 11:19:27.967: E/TelephonyProvider(833): iTelephony is null!!!
But my question is when ever i open Google maps
, it turns GPS on and off without any prompt from user
,,, thing is it only asks for first time when we login to our application, from that onwards it automatically turns on and off the GPS ,, how can i implement the same procedure implemented in google maps , better provide me with code examples thank you