Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在ICS中强制打开WiFi和GPS_Android - Fatal编程技术网

Android 在ICS中强制打开WiFi和GPS

Android 在ICS中强制打开WiFi和GPS,android,Android,我想通过代码强制打开GPS和WiFi,而不去设置,所以我没有任何关于如何在ICS中实现这一点的建议 String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (!provider.contains("gps")) { // if gps is disabled

我想通过代码强制打开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版中运行不正常。

您在问题中编写的代码以前运行良好,但由于存在安全漏洞,Android developer已经修复了几天


因此,即使您使用上述代码,它也会提供GPS闪烁动画,但在现实中它根本不起作用。即使从设备中删除应用程序,您也可以看到GPS闪烁。

请使用此代码进行手动启用,因为由于ics中的安全原因,此功能已被删除

Intent callGPSSettingIntent = new Intent(
        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(callGPSSettingIntent);

为了启用GPS,由于安全原因,Android没有提供API。因此,如果没有用户干预,您将无法启用GPS

要启用Wi-Fi

WifiManager wifiManager = new WifiManager()

if(wifiManager.isWifiEnabled())
     wifiManager.setWifiEnabled(false);

选择您想要的任何选项,可将其设置为打开或关闭。

可能重复的设置无法在ICS中打开GPS。