Reputation: 551
hi all how to implements code for displaying alert message that alert message is when system time and our given time is same then it display a message as alert("you have a new message").if our given time is 04:22:00 when system time also same as our given time then receive message as alert.so kindly help any one of you to solve this problem
Upvotes: 0
Views: 168
Reputation: 611
You'll need an AlarmManager
to wake up the system in the exact moment:
long triggerAtTime = 0;
try {
triggerAtTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.parse("2011-07-12 14:00:00").getTime();
} catch (ParseException e) {
}
Intent intent = new Intent(this, TestReceiver.class);
PendingIntent intentToSend = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
manager.set(AlarmManager.RTC_WAKEUP, triggerAtTime, intentToSend);
And a BroadcastReceiver
:
public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: notify the user
}
}
And some XML in your manifest file:
<receiver android:name=".TestReceiver"></receiver>
In the onReceive
function you can create a Toast
or a status bar Notification
:
http://developer.android.com/guide/topics/ui/notifiers/index.html
Upvotes: 1