更改Android热点设置 [英] Changing Android hotspot settings

查看:129
本文介绍了更改Android热点设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着API级别26的发布,我的应用程序的核心功能中断了,即更改了应用程序中用户的热点设置. 要获取并设置此配置,我正在使用WifiManager隐藏api中的以下功能:getWifiApConfigurationsetWifiApConfiguration.

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:

来自

深入研究代码,您将迅速发现,要成功调用此方法,您的应用程序必须拥有 android.permission.OVERRIDE_WIFI_CONFIG 权限,该权限是系统级受保护的权限:

Digging into the code you will quickly find out that to successfully invoke this method your application must hold the android.permission.OVERRIDE_WIFI_CONFIG permission that is a system level protected permission:

框架 AndroidManifest.xml的摘要

<!-- @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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆