Android Oreo 8.0+ 禁用网络权限问题

标签 android cordova android-permissions android-8.0-oreo android-8.1-oreo

我正在构建一个 Cordova 应用程序,它需要在 Android 上访问 WiFi 并禁用当前连接的网络,以防止自动断开我正在连接的网络(因为没有互联网)。

问题是,在 Android Oreo 8.0+ 上进行测试时,我在 adb logcat 中遇到了这个错误,我无法弄清楚我需要做什么来解决这个问题:

E/WifiConfigManager: UID 10315 does not have permission to update configuration "Test SSID"WPA_PSK
E/WifiStateMachine: Failed to disable network

这些是 list 中列出的权限:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
<uses-permission android:name="android.permission.INTERNET" />

我在这篇文章中找到的OVERRIDE_WIFI_CONFIG perm,但这似乎对我的具体情况没有帮助:Changing Android hotspot settings

我在这个文件中发现了这个特定的错误: https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#984

它调用了我在这里找到的 canModifyNetwork: https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#651

任何对 Android 更有经验的人都可以帮助我解决这个问题,需要做什么才能让我的应用禁用网络?

这是否意味着如果网络不是由应用创建的,则不允许应用禁用网络??请帮助我不知道从这里去哪里!

我确实也找到了这篇文章,它引用了 6.0,但是我们基本上完全被禁止禁用我们没有创建的网络是真的吗? Android 6.0 Cannot add WifiConfiguration if there is already another WifiConfiguration for that SSID

最佳答案

我无法回答你的问题,但我可以回答这个问题

Does this mean that apps are not allowed to disable a network if it wasn't created by the app?

这是正确的,根据 documentation禁用网络方法:

Disable a configured network. The specified network will not be a candidate for associating. This may result in the asynchronous delivery of state change events. Applications are not allowed to disable networks created by other applications.

所以如果用户已经使用Android系统连接到这个网络,在Oreo中你将无法禁用网络。 尽管方法 disableNetwork 在成功或失败的情况下返回 true 或 false

关于Android Oreo 8.0+ 禁用网络权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48308038/

相关文章:

java - Flutter,访问隐藏方法

Android:如何完全禁用 Edittext 中的复制和粘贴功能

android - Android 13 Tiramisù 上异常权限请求行为

Android 6.0 - 无需请求许可即可将文件下载到外部存储

java - 安全异常 : No persistable permission grants found for uri from ACTION_IMAGE_CAPTURE

android - google-services.json在创建我的应用程序的产品样式时导致问题,可能的解决方法?

android - 从另一个 Activity 启用按钮

javascript - Cordova /AngularJS/ ionic : Check if online and domain reachable

angular - 与cordova成 Angular location.back路由问题

cordova - apache cordova 和 ionic 有什么区别?