gpt4 book ai didi

java - 问 - 切换用户的全局设置(WiFi、位置等) - 2 个想法.. 有什么想法吗?

转载 作者:太空宇宙 更新时间:2023-11-04 12:15:39 25 4
gpt4 key购买 nike

我的问题:如何关闭用户的全局设置之一(例如“位置”或“蓝牙”或“WiFi”等)..?

在得知我无法通过权限执行此操作后,我想出了一些关于可能如何做到这一点的其他想法/想法,并且需要一些说明!

( 1 ) - 获得“电话管理员”权限(类似于 NOVA 等启动器执行某些操作的方式)是否有效?注意:我指的是您可能会在(设置 > 锁定屏幕和安全 > 其他安全设置 > 手机管理员)中找到的应用程序。

或者..

( 2 ) - 成为“设备所有者”(如 Android Studio 中的“设备所有者”Android 代码示例)会有什么帮助吗?

:/

此时我完全没有想法,并且不希望我迄今为止的工作白白浪费。请注意,我实际上是在尝试关闭某个设置,而不是打开。但我怀疑这会产生任何影响。

如果有人可以为我提供上述问题的答案,我将不胜感激!任何信息都会对我有很大帮助!
谢谢!:)

最佳答案

对于 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" />

对于位置,请尝试以下操作:(注意:在 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);
}
}

我希望这能帮助您解决问题,如果问题仍然存在,或者您想知道如何打开/关闭其他全局设置,请搜索此论坛,我相信您会找到有用的东西。

关于java - 问 - 切换用户的全局设置(WiFi、位置等) - 2 个想法.. 有什么想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39438982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com