M.V*_*.V. 3 notifications android
我想询问哪些服务以及如何在android中使用提醒...让我们说:从现在起10分钟后,在通知栏中显示通知...
感谢您的回答
小智 9
显然你应该使用AlarmManager来设置在给定的PERIOD中执行的东西.
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);
Run Code Online (Sandbox Code Playgroud)
其中PERIOD是你应该在OnAlarmReceiver中执行的东西的时间.然后,只需实现方法
@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);
}
Run Code Online (Sandbox Code Playgroud)
请享用.
| 归档时间: |
|
| 查看次数: |
3971 次 |
| 最近记录: |