失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android 强制开启wifi android-在ICS中强制打开WiFi和GPS

android 强制开启wifi android-在ICS中强制打开WiFi和GPS

时间:2020-06-20 10:18:50

相关推荐

android 强制开启wifi android-在ICS中强制打开WiFi和GPS

我想通过代码强制打开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》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。