我知道这个问题在这里有很多问题,但只是想知道自从ICS发布以来,是否有办法以编程方式启用gps?
我正在尝试启用gps并将设备的位置发送到电子邮件,应用程序将在收到短信时启动.
当我尝试在我的Android 4.4 (Kitkat)上启用GPS时,我的Android应用程序崩溃了.它一直运行良好,直到Android 4.3.我正在使用以下代码打开GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
在我的Log Cat中给出安全例外.
我的LogCat详细信息如下: -
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)
Run Code Online (Sandbox Code Playgroud)
当我评论代码时,它的工作正常.是否有任何特定参数可在Android 4.4上手动启用GPS.