我的问题: 如何关闭用户的全局设置之一(例如"位置"或"蓝牙"或" WiFi"等)。 ?
在学习之后我无法通过权限做到这一点,我想出了一些关于可能如何做的其他想法/想法,需要一些澄清!
(1) - 将获得"电话管理员"特权(类似于NOVA等发射器执行某些操作的方式)有效吗? 注意:我指的是您可以找到的应用(设置>锁屏和安全>其他安全设置>手机管理员)。
OR .. 的
(2) - 将成为"设备所有者" (比如设备所有者" Android Studio中的Android代码示例)会有什么帮助吗?
:/
我现在完全失去了想法,并且不想让我的工作到目前为止浪费掉...... 请注意,我实际上是试图关闭一个设置,而不是..但我怀疑这有什么不同......
如果有人可以请我提供上述问题的答案,我将不胜感激! 任何信息都会对我有很大的帮助! 谢谢!:)
答案 0 :(得分:0)
对于Wifi,请尝试以下操作:
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true); //TURN WIFI ON
wifiManager.setWifiEnabled(false); //TURN WIFI OFF
另外,将其添加到您的AndroidManifest.xml
文件中:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
对于蓝牙,请尝试以下操作:
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
bluetooth.disable();
bluetooth.enable();
并将其添加到您的AndroidManifest.xml
文件中:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
对于位置,请尝试以下操作:(注意:不允许/&#34;可能&#34;在Android 4.0及更高版本上打开/关闭GPS /位置,但有些报道这种解决方法可能有效)
public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.ctx.sendBroadcast(intent);
String provider = Settings.Secure.getString(ctx.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"));
this.ctx.sendBroadcast(poke);
}
}
// automatic turn off the gps
public void turnGPSOff()
{
String provider = Settings.Secure.getString(ctx.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"));
this.ctx.sendBroadcast(poke);
}
}
我希望这可以帮助您解决问题,如果问题仍然存在,或者您想知道如何打开/关闭其他全局设置,请搜索此论坛,我相信您已经确定了找到有用的东西。