
我希望我的通知每天中午12:00运行.如何用时间替换when值?
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);解决方法:
您可以使用警报管理器
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并将通知放在myService类中!
总结以上是内存溢出为你收集整理的android – 将通知设置为特定时间全部内容,希望文章能够帮你解决android – 将通知设置为特定时间所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)