我想通过code对GPS进行切换。以下是code我用。
I am trying to switch on GPS by code. The following is the code I've used.
String provider = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
在code执行中的onReceive功能。我究竟做错了什么?
The code executing in OnReceive function. What am I doing wrong?
Android的指导方针在4.0以上版本的改变。您不能以编程方式更改GPS关闭在4.0以上的版本。但是,您可以以编程方式更改WiFi关闭
Android Guidelines have changed above version 4.0. You cannot change GPS off on programmatically for versions above 4.0. However, you can change wifi off on programmatically