在特定的时间,每天的android通知

编程入门 行业动态 更新时间:2024-10-19 21:21:46
本文介绍了在特定的时间,每天的android通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想做出让用户决定什么时候每天要他提醒一些与通知的应用程序...

I'd like to make an app that let the user decide what time everyday wants him to remind something with notification...

我想知道我怎么来触发secific时间用户希望前7:00的通知,让他挖掘的通知,然后在特定的活动中的应用。但是,当用户不希望得到更多的通知(一个按钮点击)我如何取消所有的通知...?

I'd like to know how am i supposed to trigger a notification in secific time the user wants e.x 7:00am and make him tap on the notification and enter the application in specific activity. But when the user doesn't want to get any more notifications (with a button click) how am i cancel all the notifications...?

我做的东西像

Intent intent = new Intent(this, main.class); Bundle bundle = new Bundle(); bundle.putString("title", "Some Title");\ intent.putExtras(bundle); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); String body = "Tap to see the Activity"; String title = "Title of notification"; Notification n = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis()); n.setLatestEventInfo(this, title, body, pi); n.defaults = Notification.DEFAULT_ALL; nm.notify(uniqueID, n);

但没有运气到现在为止....

but no luck until now....

谢谢...

<< >>

<<>>

我这样做

String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.notification_icon; CharSequence tickerText = "Ome TickerText"; long when = System.currentTimeMillis(); Context context = getApplicationContext(); CharSequence contentTitle = "Some Title"; CharSequence contentText = "Some Text"; Intent notificationIntent = new Intent(context, LandingActivity.class); Bundle bundle = new Bundle(); bundle.putString("title", "a title"); bundle.putString("title2", "title number 2"); bundle.putString("action", "tip"); bundle.putString("greek", "somehting else"); bundle.putInt("action_num", 2); notificationIntent.putExtras(bundle); alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); contentIntent = PendingIntent.getActivity(Notifications.this, 0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.defaults = Notification.DEFAULT_ALL; mNotificationManager.notify(UniqueID, notification); int hour = tp.getCurrentHour(); int minutes = tp.getCurrentMinute(); contentIntent = PendingIntent.getService(Notifications.this, 0, notificationIntent, 0); AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, 00); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), contentIntent);

但没有luckk ...

but no luckk...

任何帮助吗?

推荐答案

使用报警经理,把你的通知 NotifyService 类

Intent myIntent = new Intent(Current.this , NotifyService.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

更多推荐

在特定的时间,每天的android通知

本文发布于:2023-11-27 08:18:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637252.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   时间   在特定   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!