I have a running Android app, which sends data to a server. If the device is not connected to the internet, it should be possible to save the data temporarily on the device. If the device retrieves the connection, it should send the saved data to the server. Even if the app is closed.

My question is, how to create a "listener" which listens on the internet connection? This mechanic should work like WhatsApp. In WhatsApp you can receive messages, even when the app is closed.

I've looked a bit around....could this be a Widget? And if it is one, how to not display it on the Home screen? I don't need to display any information there.

有帮助吗?

解决方案

You can register for changes to connectivity by following the instructions at Monitor for Changes in Connectivity. When you hear that the phone has connectivity, send your data.

Sorry, I don't know enough about widgets to advise whether they'd be a good fit here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top