Android Q - 未经批准连接wifi [英] Android Q - Connect wifi without approval

查看:50
本文介绍了Android Q - 未经批准连接wifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个自动连接到 Wifi 的应用程序.你会在下面找到我的代码,它运行良好!

I'm developing an app which connect to Wifi automatically. You will find my code below, which works well !

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    boutonConnecter.setOnClickListener {
        val wifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
            .setSsid("MYSSID")
            .setWpa2Passphrase("MyPassphrase")
            .build()

        val networkRequest = NetworkRequest.Builder()
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
            .setNetworkSpecifier(wifiNetworkSpecifier)
            .build()

        val connectivityManager =
            applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

        connectivityManager.requestNetwork(
            networkRequest,
            ConnectivityManager.NetworkCallback()
        )


    }
}

但似乎对于 Android Q (android 10),在连接之前,应用程序需要用户批准!它会打开一个弹出窗口,用户需要选择网络(批准).

But it seems that with Android Q (android 10), before connecting, the app needs the user approval ! It opens a pop-up and the user needs to select the network (approval).

是否可以绕过"用户批准?我想直接连接到 wifi,无需征得用户同意...

Is it possible to "bypass" the user approval ? I'd like to connect directly to wifi without asking the user's approval...

有可能吗?

推荐答案

不,这在 Android 10 中是不可能的.此更改是为了用户隐私而购买到 Android 10 的.请参阅此处的官方文档:https://developer.android.com/about/versions/10/privacy/changes#enable-disable-wifi

No, It is not possible from Android 10. This change was bought to Android 10 for user privacy. See official documentation here : https://developer.android.com/about/versions/10/privacy/changes#enable-disable-wifi

这篇关于Android Q - 未经批准连接wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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