how to implements code for receiving a alert message?
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开发者_Python百科 given time then receive message as alert.so kindly help any one of you to solve this problem
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
精彩评论