I would suggest you to write an Activity
. Set Alarm for every 5 minutes in the onCreate() method as follows:
Intent intent = new Intent(this, ServiceForAlarm.class);
intent.setAction(""+System.currentTimeMillis());
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(m_Context, 0, intent, Intent.FLAG_GRANT_READ_URI_PERMISSION);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(), 300000L, pendingIntent);
In the ServiceForAlarm
, write code to push notifications.
public class ServiceForAlarm extends Service {
private Context mContext;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
mContext = getApplicationContext();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
SetNotification();
stopSelf();
}
private void SetNotification() {
m_NotificationManager = (NotificationManager)m_Context.getSystemService(Context.NOTIFICATION_SERVICE);
m_Notification = new Notification(R.drawable.icon_app, "Your message", System.currentTimeMillis());
m_Intent = new Intent() ;
m_PendingIntent = PendingIntent.getActivity(m_context, 0, m_Intent, 0);
m_Notification.contentIntent = m_PendingIntent;
m_Notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
m_Notification.setLatestEventInfo(m_context, "Title", "Click me", m_PendingIntent);
m_NotificationManager.notify(1010, m_Notification);
}
}