Get updates from a server in the background using Pull notification - Android

巧了我就是萌 提交于 2019-12-10 21:07:05

问题


I want to implement a feature in an android app, which periodically pulls information from a server even when the app is in the background / not running.

It should invoke a web service and check for updates at least 3-4 times in a day, and if available pull and show them in the notification bar. When the user clicks on the notification it should open up the app screen.

Is that feasible using pull notification technology? Are there any constraints? Can you share some tutorials that will help me implement this.

Thanks..


回答1:


Sudo steps hope these helps you to go ahead.

  1. Create One Service This service will call server and gets the updated if available and generate the Notification.
  2. Set Repeat Alarm using AlarmManger When application launches first time every 8 hours that is 4 times in a day.
  3. Create BroadCastReceiver which will called by alarm manager every 8 hours.
  4. And From BroadcastReceive's onReceive() method start the Service for data sync.

I pretend that you know AlarmMAnager,Service and BroadcastReceiver.

The working tutorial is Here

Thanks



来源:https://stackoverflow.com/questions/26463751/get-updates-from-a-server-in-the-background-using-pull-notification-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!