[英]Android - How to check whether other user is connected to internet?
Is there a way to check whether the other user (having my app installed) is connected to internet or not even when the user's phone is at sleep mode? 有没有一种方法可以检查另一个用户(已安装我的应用程序)是否已连接到Internet,即使该用户的手机处于睡眠模式也是如此?
I want to do something like: 我想做类似的事情:
if (uid is connected)
{
perform certain task;
}
else if (uid is not connected)
{
show a message;
}
where uid
is some unique user id. uid
是一些唯一的用户ID。
I would say implement something like Socket
, through which you would be able to instantly get who all users are active and connected. 我想说的是实现
Socket
东西,通过它您可以立即获得所有活动和连接的用户的身份。 Like how most of the application does sync operation when you wake up in the morning or when your phone is not in the doze mode. 就像早上醒来或手机未处于打ze模式时,大多数应用程序如何进行同步操作一样。
Android operating system manages doze mode and so it decides itself whether the phone is in use or away from use during night time. Android操作系统管理打ze模式,因此它会自行决定手机在夜间使用还是停止使用。 During the doze time, only priority and needed processes would continue working, rest of all the processes will be forced to kill, here our app won't run and so socket connectivity will be offline.
在休眠期间,只有优先级和所需的进程将继续运行,所有进程的其余部分将被强制终止,此处我们的应用程序将无法运行,因此套接字连接将脱机。 As soon as it comes out from the doze mode, the socket will be reconnected and that's where you need put some tasks again.
从休眠模式中出来后,套接字将重新连接,这是您需要再次放置一些任务的地方。
My 2 cents on how we can achieve this, there would be other ways as well! 我关于如何实现这一目标的2美分,还有其他方法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.