简体   繁体   English

Android:通过蓝牙连接两个设备并以编程方式启用互联网访问

[英]Android : connect two devices by bluetooth and enable internet access programmatically

I'm trying to connect two Android devices (already paired) by Bluetooth and enable automatically access to Internet in one of them.我正在尝试通过蓝牙连接两台 Android 设备(已配对),并在其中一台设备中自动访问互联网。

This is possible by accessing in settings and enabling the below check case:这可以通过访问设置并启用以下检查案例来实现:

在此处输入图像描述

Do you have any idea how can i do this programmatically?您知道如何以编程方式执行此操作吗?

Thanks.谢谢。

This should be possible using WifiManager 's setWifiApEnabled() method.这应该可以使用WifiManagersetWifiApEnabled()方法来实现。

However, this method is only available up to Android SDK 27. It is marked as a SystemAPI and requires android.Manifest.permission.TETHER_PRIVILEGED .但是,此方法仅在 Android SDK 27 以下可用。它被标记为 SystemAPI,并且需要android.Manifest.permission.TETHER_PRIVILEGED

It is therefore strongly unrecommended to implement this functionality for the reason that Google doesn't provide any official API call for enabling the mobile hotspot.因此,强烈不建议实现此功能,因为 Google 没有提供任何官方 API 调用来启用移动热点。

You can read more about this topic here:您可以在此处阅读有关此主题的更多信息:

https://medium.com/@jean.creuzedeschatelliers/how-to-activate-the-mobile-hotspot-on-android-programmatically-or-not-5931e44097e3 https://medium.com/@jean.creuzedeschatelliers/how-to-activate-the-mobile-hotspot-on-android-programmatically-or-not-5931e44097e3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM