
我有一个Notification.Builder,只要我点击一个按钮就会向通知栏发送一条消息.有没有办法让通知在选定的时间出现?我查看了Android文档,但没有看到任何看起来会起作用的东西.
这是我的代码片段:
Notification n = new Notification.Builder(this) .setContentTitle("Random Title") .setContentText("Random text") .setSmallicon(R.drawable.abc_ic_go_search_API_mtrl_Alpha) .setContentIntent(pIntent).build(); notificationmanager notificationmanager = (notificationmanager) getSystemService(NOTIFICATION_SERVICE); notificationmanager.notify(0, n);谢谢!
解决方法:
1)使用您的通知代码创建广播接收器.
public class AlarmReceiver extends broadcastReceiver{ @OverrIDe public voID onReceive(Context context, Intent intent) { notificationmanager notificationmanager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context) .setContentTitle("Random Title") .setContentText("Random text") .setSmallicon(R.drawable.abc_ic_go_search_API_mtrl_Alpha) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MyActivity.class), 0)) .build(); notificationmanager.notify(0, notification); }}2)使用AlarmManager安排闹钟以广播您的广播接收器的意图.
AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);Intent intent = new Intent(this, AlarmReceiver.class);PendingIntent alarmIntent = PendingIntent.getbroadcast(this, 0, intent, 0);// set for 30 seconds lateralarmMgr.set(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis() + 30000, alarmIntent); 总结 以上是内存溢出为你收集整理的Android:在某个时间点击Notification.Builder全部内容,希望文章能够帮你解决Android:在某个时间点击Notification.Builder所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)