当应用程序处于前台状态时,检测Android 7.0牛轧糖上的连接更改 [英] Detect connectivity changes on Android 7.0 Nougat when app is in foreground

查看:62
本文介绍了当应用程序处于前台状态时,检测Android 7.0牛轧糖上的连接更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

牛轧糖改变了它处理CONNECTIVITY_CHANGED意图的方式(基本上忽略了它,迫使开发人员使用作业调度程序),所以这让我想知道:

Nougat changed the way it handles CONNECTIVITY_CHANGED intents (basically ignoring it, forcing devs to use the job scheduler) so this leaves me wondering:

如果我有一个正在检索某些数据的应用程序(并且我在发出请求时检查了手机是否在线,但是用户在移动中,并且手机连接到另一个wifi接入点例如),但失败了,如何检测到连接已恢复并且我可以重试查找数据?

If I have an app that is in the middle of retrieving some data (and I checked if the phone was online at the time I did the request but the user is on the move and the phone connects to a different wifi access point, for example) and it fails, how do I detect that the connection has been restored and I cam retry fetxhing the data?

因此,在这种情况下,我的应用程序处于前台,我认为Chrome(适用于android)具有类似的功能.

So in this case my app is in the foreground, I think Chrome (for android) has a similar function.

我需要自己轮询吗?还是当时允许某些事件?

Do I need to poll it myself? Or is there some event that is allowed at that time?

推荐答案

正在运行的应用程序如果请求使用BroadcastReceiver进行通知,则仍可以在其主线程上监听CONNECTIVITY_CHANGE.

Apps that are running can still listen for CONNECTIVITY_CHANGE on their main thread if they request notification with a BroadcastReceiver.

https://developer.android.com/about/versions/nougat/android-7.0-changes.html

这篇关于当应用程序处于前台状态时,检测Android 7.0牛轧糖上的连接更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆