getAllNetworkInfo()是德precated [英] getAllNetworkInfo() is Deprecated
本文介绍了getAllNetworkInfo()是德precated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写这篇code。
ConnectivityManager connectivity = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {}
但getAllNetworkInfo()是德precated。请帮忙。谢谢你。
But getAllNetworkInfo() is deprecated. Please help. Thank you.
推荐答案
作为文档说:
getAllNetworkInfo()
这个方法在API级别23.此方法不支持相同类型的多个连接的网络pcated德$ P $。使用 getAllNetworks()
和 getNetworkInfo(android.net.Network)
代替。
This method was deprecated in API level 23. This method does not support multiple connected networks of the same type. Use
getAllNetworks()
andgetNetworkInfo(android.net.Network)
instead.
我认为你可以使用 getActiveNetworkInfo()
:
下面是code:
ConnectivityManager connectivity = (ConnectivityManager)
MainActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo nInfo=connectivity.getActiveNetworkInfo();
if (nInfo != null && nInfo.getState()== NetworkInfo.State.CONNECTED) {
//do your thing
}
}
这篇关于getAllNetworkInfo()是德precated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文