android - 如何获取有关断开网络的详细信息?
问题描述
有没有办法使用android广播接收器或networkcallback获取有关断开网络的详细信息?
EXTRA_NETWORK_INFO、getNetworkInfo(NetworkType) 已弃用。
getAllNetworks() 返回框架当前跟踪的所有网络的数组,但不返回断开连接的网络。
解决方案
是的,首先像这样注册广播接收器:
final IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(receiver, intentFilter);
当接收者是:
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// this part is trigered when there is some network changes, do checks here
}
};
也不要忘记注销它。
推荐阅读
- python - 如何修复未打开的ui页面?
- c# - Xamarin.Forms 可以通过 Wi-FI 在 iPhone(真实设备)上工作,而无需连接到来自 VS 2019 CE Windows 10 的真实 Mac Os?
- javascript - 在 typescript 和 webpack 中访问 fs 模块
- c++ - 获取:-1:错误:[Makefile.Debug:71: debug/Tappian_Ball.exe] 尝试使用 LIBS 时出现错误 1
- flutter - Flutter - 如何更改推送通知背景颜色
- angular - 使用 --user 将 curl 请求转换为 angular http
- azure - 无法将 Azure 仪表板卡设置为使用“在查询中设置”
- node.js - 通过 webdriver.io 运行时,如何找到失败的 cucumber-js 步骤的行号?
- android - Android Emulator 的 Overlay 占据 Linux 桌面的区域
- webpack - 使用 webpack-dev-server 时 msw 初始化的公共目录应该是什么?