将通知具体时间 [英] Set notification to specific time

查看:100
本文介绍了将通知具体时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的通知在中午12点的日常运行。你如何与时间更换,当值?

  NotificationManager纳米=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
通知通知=新的通知(R.drawable.icon,它吃的时候,当);

上下文的背景下= GrubNOWActivity.this;
CharSequence的标题=它吃的时候;
CharSequence的细节=点击这里搜索餐馆;
意向意图=新的意图(背景下,Search.class);
PendingIntent未决= PendingIntent.getActivity(上下文,0,意图,0);
notify.setLatestEventInfo(背景下,职称,详细信息,待定);
nm.notify(0,通知);
 

解决方案

您可以使用报警管理器

 意图myIntent =新的意图(ThisApp.this,myService.class);
       AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);
       pendingIntent = PendingIntent.getService(ThisApp.this,0,myIntent,0);

       台历挂历= Calendar.getInstance();
           calendar.set(Calendar.HOUR_OF_DAY,12);
       calendar.set(Calendar.MINUTE,00);
       calendar.set(Calendar.SECOND,00);

      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),24 * 60 * 60 * 1000,pendingIntent); //设置重复,每24小时
 

和把该通知为myService类中!

I would like my notification to run at 12:00pm everyday. How do you replace the when value with a time?

NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.icon,"Its Time to Eat",when);

Context context = GrubNOWActivity.this;
CharSequence title = "Its Time to Eat";
CharSequence details = "Click Here to Search for Restaurants";
Intent intent = new Intent(context,Search.class);
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
notify.setLatestEventInfo(context, title, details, pending);
nm.notify(0,notify);

解决方案

You can use an alarm manager

Intent myIntent = new Intent(ThisApp.this , myService.class);     
       AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
       pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);

       Calendar calendar = Calendar.getInstance();
           calendar.set(Calendar.HOUR_OF_DAY, 12);
       calendar.set(Calendar.MINUTE, 00);
       calendar.set(Calendar.SECOND, 00);

      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent);  //set repeating every 24 hours

and put the notification inside myService class!

这篇关于将通知具体时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆