开发者

Android Reminder Application

开发者 https://www.devze.com 2023-03-31 11:01 出处:网络
I need to create reminder application based on the date and time from the database (Eg:31-08-2011 10:30,05-09-2011 14:40,etc.. )even if the app is not runn开发者_如何转开发ing.. Database will contain

I need to create reminder application based on the date and time from the database (Eg:31-08-2011 10:30,05-09-2011 14:40,etc.. )even if the app is not runn开发者_如何转开发ing.. Database will contain many dates with times. If the time reaches i need to display the notificaiton.How can I do that. Please provide any samples or suggestions


You should use AlarmManager for this.

AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, OnAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
SystemClock.elapsedRealtime(), PERIOD, pi);

where the PERIOD is your time to something that should be executed in OnAlarmReceiver. And then, just implement method in

@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    notification.tickerText = "10 Minutes past";
    nm.notify(0, notification);
}

And also see here,

http://developer.android.com/reference/android/app/AlarmManager.html

Edit: A minor code issue fixed!


Put this code wherever you need..

new CountDownTimer(diff, 1) //Constructor for CountDownTimer class (milliseconds,difference);
{
public void onTick(long millisUntilFinished)
{
// DO NOTHING
}

public void onFinish() {
sendSMS(phoneNo,message);
}
}.start();
0

精彩评论

暂无评论...
验证码 换一张
取 消