Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
我在主要的Java类中使用了上面的代码,但是没有用。还有其他办法吗?
最佳答案
这个问题被讨论了很多次。据我所知,您无法从Android 4.0.3自动执行此操作。如果您使用的是Android 2+,则是否将以下行添加到AndroidManifest。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
有另一种方法。即使用Google设置API。
com.google.android.gms:play-services:8.1.0
检查Google Samples
还要检查this问题。