java 网络状态改变时的广播意图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2676044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:19:16  来源:igfitidea点击:

Broadcast Intent when network state has changend

javaandroidbroadcastreceiver

提问by user283494

Does Android broadcast an intent when the network state has changend, i.e. from GSM to Wifi? And if so what permission do I need and what is the intent action called?

当网络状态发生变化时,即从 GSM 到 Wifi,Android 是否会广播意图?如果是这样,我需要什么许可以及所谓的意图操作是什么?

回答by velazcod

Update:please use this instead: https://stackoverflow.com/a/2677519/241869

更新:请改用这个:https: //stackoverflow.com/a/2677519/241869

回答by Al.

There isn't anything exactly like what you are describing but you can use ConnectivityManager.CONNECTIVITY_ACTIONto monitor changes and use the extras that come with it to see if the connection has changed from GSM to Wifi and vice versa. For this you need the permission android.permission.ACCESS_NETWORK_STATEand android.permission.ACCESS_WIFI_STATEfor checking wifi information.

没有任何与您所描述的完全相同的东西,但您可以使用它ConnectivityManager.CONNECTIVITY_ACTION来监视更改并使用随附的附加功能来查看连接是否已从 GSM 更改为 Wifi,反之亦然。为此,您需要获得许可android.permission.ACCESS_NETWORK_STATEandroid.permission.ACCESS_WIFI_STATE检查 wifi 信息。

回答by Erich Douglass

Android will broadcast WifiManager.NETWORK_STATE_CHANGED_ACTIONwhen the devices gains or looses wifi connectivity. You'll need the permission android.permission.ACCESS_WIFI_STATEto receive the intent. However, I'm not sure if there's something similar for GSM -> WIFI.

WifiManager.NETWORK_STATE_CHANGED_ACTION当设备获得或失去 wifi 连接时,Android 将进行广播。您需要获得许可android.permission.ACCESS_WIFI_STATE才能接收意图。但是,我不确定 GSM -> WIFI 是否有类似的东西。