问题
I'm looking for a way to allow a device to send secure notifications to another device with minimal battery loss. I am currently doing this using a SSLServerSocket however I feel like keeping a socket constantly open is very poor for battery life. The other option I considered was to just have a socket listening for a connection but I'm not sure if this is any better. I need the notifications to be sent instantly so using a timer and connecting every x number of minutes is not optimal. Are there any good ways to achieve this over a wifi connection with minimal battery loss?
回答1:
perhaps you can use C2DM (Cloud2DeviceMessaging). This may not be the perfect solution for you but instead of all the devices asking all the time for updates the server tells them they do.
Device A send a message to Device B -> Device A sends the message to the server -> Server notifies Device B that it has a message -> Device B asks the server for that message
来源:https://stackoverflow.com/questions/10307625/communication-between-android-devices