Android 10自动连接WiFi问题 Android 10 断开WiFi问题

  1. 说明:本文主要说明扫码之后自动连接WiFi的一些处理,扫码的流程相对简单,网上教程也比较多,对于目前Android各个版本也没有太多变化。
  2. 问题描述:最近在做项目的时候,发现以前的项目有扫描二维码自动连接WiFi的功能,设备改了生成二维码的方式,然后发现手机无法自动连接WiFi了。
  3. 问题原因:经过代码调试发现:(我都是真机调试)
    wifiManager.addNetwork(WifiConfiguration);
    在添加WiFi的时候,这行代码始终返回-1,换用同事手机竟然神奇的可以连接,然后一脸蒙蔽,裂开了,不怕有问题,就怕有的有问题,有的没问题。
  4. 问题解决:
  • 区别:我测试手机 小米10 android Q(andorid 10)的系统,同事手机荣耀 android P的系统,大胆猜测是不是android 10又搞了什么奇怪的东西
  • 根因:皇天不负有心人,上代码:
    /**
         * Add a new network description to the set of configured networks.
         * The {@code networkId} field of the supplied configuration object
         * is ignored.
         * <p/>
         * The new network will be marked DISABLED by default. To enable it,
         * called {@link #enableNetwork}.
         *
         * @param config the set of variables that describe the configuration,
         *            contained in a {@link WifiConfiguration} object.
         *            If the {@link WifiConfiguration} has an Http Proxy set
         *            the calling app must be System, or be provisioned as the Profile or Device Owner.
         * @return the ID of the newly created network description. This is used in
         *         other operations to specified the network to be acted upon.
         *         Returns {@code -1} on failure.
        
  • 13
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 32
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 32
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值