Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android app crash on android 4.4 due to gps permission denial

My android app is crashing when I try to enable GPS on my android 4.4 (Kitkat). It's been working fine till Android 4.3 . I am using following code to turn on GPS

Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent);

In my Log Cat its giving security exception.

My LogCat details are as :-

11-27 12:47:37.410: E/AndroidRuntime(3818): Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=3818, uid=10084
11-27 12:47:37.410: E/AndroidRuntime(3818):  at android.os.Parcel.readException(Parcel.java:1461)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at android.os.Parcel.readException(Parcel.java:1415)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2373)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at com.sus.SUSV7_1.Activity.Splash_ScreenActivity.turnGPSOn(Splash_ScreenActivity.java:66)
11-27 12:47:37.410: E/AndroidRuntime(3818):  at com.sus.SUSV7_1.Activity.Splash_ScreenActivity.onCreate(Splash_ScreenActivity.java:26)

When I comment the code then its working fine. Is there any specific parameter to enable GPS manually on Android 4.4.

like image 298
Praveen Sharma Avatar asked Nov 27 '13 07:11

Praveen Sharma


Video Answer


1 Answers

This never was meant to be public API.

There even is an issue on AOSP bug tracker regarding this topic: https://code.google.com/p/android/issues/detail?id=35924

I guess, they just fixed this security whole.

You might want to direct the user to change the GPS settings:

startActivity(context, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
like image 174
flx Avatar answered Sep 27 '22 16:09

flx