更改Android热点设置 [英] Changing Android hotspot settings
问题描述
随着API级别26的发布,我的应用程序的核心功能中断了,即更改了应用程序中用户的热点设置.
要获取并设置此配置,我正在使用WifiManager
隐藏api中的以下功能:getWifiApConfiguration
和setWifiApConfiguration
.
With the release of API level 26, my app's core functionality broke, this being, changing the users' hotspot setting within the application.
To get and set this configuration I am using the following functions from the WifiManager
hidden api: getWifiApConfiguration
and setWifiApConfiguration
.
Method getWifiApConfiguration = wifiManager.getClass().getMethod("getWifiApConfiguration");
getWifiApConfiguration.invoke(wifiManager);
这适用于Android O之前的设备,但在此版本中,我收到以下错误消息:
This is working with devices prior to Android O, but in this version I get the following error:
不允许应用读取或更新存储的WiFi Ap配置(uid = 10168)
App not allowed to read or update stored WiFi Ap config (uid = 10168)
我在清单中声明的权限是:
The permissions I have declared in the manifest are:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_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.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.NETWORK_STACK"/>
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" />
如何使用最新的API?
How can I do this with the latest APIs?
推荐答案
从Android Oreo(26)开始,将新的权限检查添加到getWifiApConfiguration()方法的服务实现中:
As of Android Oreo (26), a new permission check was added to the service implementation of the getWifiApConfiguration() method:
<!-- @SystemApi @hide Allows an application to modify any wifi configuration, even if created
by another application. Once reconfigured the original creator cannot make any further
modifications.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
android:protectionLevel="signature|privileged" />
这意味着您的应用程序需要使用平台密钥签名或具有使用此API的特权.
This means that your application needs to be signed by the platform key or be privileged to use this API.
这篇关于更改Android热点设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!