Android 6.0 wif的变动
2016-04-02 10:47
337 查看
最近项目在nexus5机子上出现崩溃,看下系统,Android 6.0,所以查看了下Google Android 6.0 的更新。立马定位到WiFi和netWoring改变这部分。Google 官方原文档是这样的。
This release introduces the following behavior changes to the Wi-Fi and networking APIs.
Your apps can now change the state of
only if you created these objects. You are not permitted to modify or delete
created by the user or by other apps.
Previously, if an app forced the device to connect to a specific Wi-Fi network by using
the
lower, it is pinned to the selected Wi-Fi network. If your app’s
and the new
to ensure that its network traffic is sent on the selected network.
(英语学渣的理解)
第一条是,你的app现在不能改变wificonfiguration对象的状态,只能创建它。你不允许去修改和删除用户创建或者其他app创建的wificonfiguration对象。
第二条是,以前你的app可以强制你的设备去连接指定的WiFi网络通过调用enableNetwork()方法。合适使用disableAllothers = true,来使设备断开其他网络,如蜂窝数据。但是在最新的6.0中设备不再断开其他网络,如果你的app targetSDKVersiond是20或者更低,它将自动的选择WiFi 网络,如果的app targetSDKVersiond是21或者更高使用多网络API(multinetwork
api Anroid 5.0里可以查阅)去确保网络数据被发送在已经选择的网络上。
第二条没有验证,但第一是引起项目崩溃的原因所在,因为Android 6.0 中WiFiManager addNetwork(WifiConfiguration config),add
同一ssid时会返回-1,这个时候你再调用enableNetWork
将这个-1NetWorkId传进去就会系统崩溃,总连不上WiFi。
我解决办法是,addNetWork之后遍历所有的WifiManager.getConfiguredNetworks(),取出相同的
ssid的wificonfiguraion.
然后在使用WifiManager.enableNetwork(wificonfiguraion.neteworkId, true);
Wi-Fi and Networking Changes
This release introduces the following behavior changes to the Wi-Fi and networking APIs.Your apps can now change the state of
WifiConfigurationobjects
only if you created these objects. You are not permitted to modify or delete
WifiConfigurationobjects
created by the user or by other apps.
Previously, if an app forced the device to connect to a specific Wi-Fi network by using
enableNetwork()with
the
disableAllOthers=truesetting, the device disconnected from other networks such as cellular data. In This release, the device no longer disconnects from such other networks. If your app’s
targetSdkVersionis
“20”or
lower, it is pinned to the selected Wi-Fi network. If your app’s
targetSdkVersionis
“21”or higher, use the multinetwork APIs (such as
openConnection(),
bindSocket(),
and the new
bindProcessToNetwork()method)
to ensure that its network traffic is sent on the selected network.
(英语学渣的理解)
第一条是,你的app现在不能改变wificonfiguration对象的状态,只能创建它。你不允许去修改和删除用户创建或者其他app创建的wificonfiguration对象。
第二条是,以前你的app可以强制你的设备去连接指定的WiFi网络通过调用enableNetwork()方法。合适使用disableAllothers = true,来使设备断开其他网络,如蜂窝数据。但是在最新的6.0中设备不再断开其他网络,如果你的app targetSDKVersiond是20或者更低,它将自动的选择WiFi 网络,如果的app targetSDKVersiond是21或者更高使用多网络API(multinetwork
api Anroid 5.0里可以查阅)去确保网络数据被发送在已经选择的网络上。
第二条没有验证,但第一是引起项目崩溃的原因所在,因为Android 6.0 中WiFiManager addNetwork(WifiConfiguration config),add
同一ssid时会返回-1,这个时候你再调用enableNetWork
将这个-1NetWorkId传进去就会系统崩溃,总连不上WiFi。
我解决办法是,addNetWork之后遍历所有的WifiManager.getConfiguredNetworks(),取出相同的
ssid的wificonfiguraion.
然后在使用WifiManager.enableNetwork(wificonfiguraion.neteworkId, true);
相关文章推荐
- Android Context的一些总结
- Android Studio安装插件
- 自定义view之圆形ImageView
- Android中Cursor类的概念和用法
- 强烈推荐android studio用的几个插件
- AndroidStudio配置github全攻略
- Android中fill_parent、wrap_content和match_parent的区别
- 6.4 Android Framework - StateListDrawable
- 分析Android应用使用的技术框架和开源库
- Android 消息循环机制源码分析
- PhotoView问题 ImageView no longer exists.
- Android内部文件的读取和写入
- Android 消息循环机制源码分析
- 6.3 Android Framework - LayerDrawable
- RxJava在Android中使用场景详解
- RxJava在Android中使用场景详解
- Android ADB使用之详细篇
- Android ADB使用之详细篇
- 6.2 Android Framework - ShapeDrawable
- (OK) 编译batman-adv.ko—成功—android—cm11源码—下载