如何在传入数据时唤醒 Android [英] How to wake up an Android on incoming data

查看:54
本文介绍了如何在传入数据时唤醒 Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个 Android 服务,它正在侦听数据(我尝试过 TCP 和 UDP)以在数据到达时唤醒服务/电话.

I want an Android service, which is listening for data (I have tried TCP and UDP) to wake up the service/phone when data arrives.

目前,当 IP 数据到达数据丢失时,手机保持休眠状态.这对安卓来说正常吗?我每天有几次看到 2 小时以上的睡眠,而我睡着时会睡 7 小时以上.

Currently the phone stays asleep when IP data arrives and that data is lost. Is this normal for Android? I see sleeps of 2+ hours several times a day, and 7+ hour sleeps when I am asleep.

GCM 是否提供了在消息到达时唤醒服务/电话的解决方案.

Does GCM provided a solution which wakes up a service/phone when a message arrives.

我需要在消息从服务器发送后的几秒钟内显示出来.

I need messages to be displayed within a few seconds of them being sent from the server.

这只能通过让 CPU 整天运行来实现吗?数据到达时GSM调制解调器没有中断吗?

Can this only be achieved by keeping the CPU running all day long? Is there no interrupt from the GSM modem on the arrival of data?

推荐答案

据我所知,如果您有一个通过移动数据到服务器的出色套接字连接,则该套接字连接在睡眠模式,传入的数据包会将手机从睡眠模式(短暂地)唤醒以传送数据.

As I understand it, if you have an outstanding socket connection over mobile data to a server, that socket connection is maintained while in sleep mode, and incoming packets will wake up the phone out of sleep mode (briefly) to deliver the data.

同样的情况不是适用于 WiFi(大概也不适用于硬连线以太网).您需要持有一个 WakeLock 和一个 WifiLock.

The same is not true of WiFi (and presumably not for hardwired Ethernet, either). You would need to hold a WakeLock and a WifiLock.

GCM 是否提供了在消息到达时唤醒服务/电话的解决方案.

Does GCM provided a solution which wakes up a service/phone when a message arrives.

是的,但是...

我需要在消息从服务器发送后的几秒钟内显示出来.

I need messages to be displayed within a few seconds of them being sent from the server.

首先,GCM 没有服务级别的保证.我不知道有任何解决方案,包括您可能自己推出的任何解决方案(例如,MQTT).

First, GCM has no service-level guarantee. I am not aware of any solution that does, including anything that you might roll yourself (e.g., MQTT).

其次,您不知道设备是否能够接收任何此类消息(GCM 或其他方式),因为设备可能已关闭、处于飞行模式等.

Second, you have no idea if the device is capable of receiving any such messages (GCM or otherwise), as the device may be turned off, in airplane mode, etc.

这篇关于如何在传入数据时唤醒 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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