如何以编程方式启用Android O WiFi热点 [英] How to enable Android O WiFi Hotspot programmatically

查看:258
本文介绍了如何以编程方式启用Android O WiFi热点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用 WifiManager 隐藏API来启用Wifi网络共享和创建访问点.Android上的API 26现在出现的问题是,标记 @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)已添加到 setWifiApEnabled 函数,现在调用返回false和打印以下日志:

We've been using the WifiManager hidden API to enable Wifi tethering and create an access point. The problem now with API 26 on Android is that the tag @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) was added to the setWifiApEnabled function and now that invocation returns false and the following log is printed:

W/WifiManager:PACKAGE_NAME尝试调用setWifiApEnabled enabled enabled = true

W/WifiManager: PACKAGE_NAME attempted call to setWifiApEnabled enabled = true

在阅读新文档时,它说该功能已被弃用,并将在即将发布的版本中删除,如果调用者具有适当的权限,则改用 ConnectivityManager#startTethering ,但此方法存在相同的问题没有TETHER_PRIVILEGED权限.文档中介绍的另一个选项是使用 LocalOnlyHotspot ,但这对项目没有用,因为创建的热点没有Internet连接.

Reading the new documentation, it says that the function is deprecated and will be removed in an upcoming release and to instead use ConnectivityManager#startTethering if the caller has proper permission but this approach has the same problem with no TETHER_PRIVILEGED permissions. One other option presented on the documentation is the use of LocalOnlyHotspot but this is no use to the project since the hotspot created has no Internet connectivity.

我还使用了隐藏API中的 startSoftAp 函数进行了测试,但是由于抛出了以下异常,因此没有成功的结果:

I've also tested with the startSoftAp function from the hidden API but with no successful results since the following exception is thrown:

WifiService:用户10164和当前进程都没有android.permission.NETWORK_STACK

WifiService: Neither user 10164 nor current process has android.permission.NETWORK_STACK

是否有任何变通办法来激活较新API上的Wifi热点?我也在寻找Wifi网路共享的替代方案,但唯一可行的替代方案似乎是蓝牙网路共享,但缺点是只能获得3G速度.还考虑了Wifi Aware和Wifi P2P,但是它们存在无法在设备之间共享Internet连接的问题.

Is there any workaround to activate a Wifi hotspot on newer APIs? I've also searched for alternatives to Wifi tethering but the only viable alternative seems to be Bluetooth tethering with the downside of only getting 3G speed. Wifi Aware and Wifi P2P were also considered but these have the problem of the Internet connectivity not being shared between the devices.

关于如何处理此问题的任何建议?

Any suggestions on how to approach this?

推荐答案

此问题已被回答很多次.正如Snehashish Agarwal所说,setWifiApEnabled()和startThethering()方法是私有API.它们用@hide注释,这意味着它们是私有的.第三方应用程序不应直接调用私有API.无法保证它们将来会工作.就像你的情况一样.

This has been answered many times. As, Snehashish Agarwal said, setWifiApEnabled() and startThethering() methods are private APIs. They are annotated with @hide which means they are private. Third party applications should not be invoking private APIs directly. There is no guarantee that they will work in future. As in your case.

此外,

Also, startLocalOnlyHotspot will not have the internet access. It is a local only hotspot to communicate between devices connected to the Wifi hotspot and this method will not have Internet access.

当前,尚无用于启用移动热点的官方API调用.

Currently, there are no official API call for enabling the Mobile hotspot.

这篇关于如何以编程方式启用Android O WiFi热点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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