我想通过代码强制打开GPS和WiFi,而无需进行设置,因此我对如何在ICS中实现这一点提出了任何建议.
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!provider.contains("gps")) { // if gps is disabled
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"));
sendBroadcast(poke);
}
这段代码在2.1中可以正常工作,但在ICS中则不能.
解决方法:
请使用此代码进行手动设置,因为由于ics中的安全原因,此功能已被删除.
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
标签:android
来源: https://codeday.me/bug/1122/2061066.html
如果觉得《android 强制开启wifi android-在ICS中强制打开WiFi和GPS》对你有帮助,请点赞、收藏,并留下你的观点哦!