gpt4 book ai didi

android - android 每天特定时间通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:16 25 4
gpt4 key购买 nike

我想制作一个应用程序,让用户决定每天什么时候希望他通过通知来提醒某事...

我想知道我应该如何在用户想要的特定时间触发通知,例如早上 7:00,并让他点击通知并进入特定 Activity 的应用程序。但是,当用户不想再收到任何通知时(通过单击按钮),我该如何取消所有通知...?

我做了类似的东西

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);

但直到现在都没有运气......

谢谢...

<<>>>

我在做这个

        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);

但是运气不好...

有什么帮助吗?

最佳答案

使用警报管理器并将您的通知放入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(), AlarmManager.INTERVAL_DAY , pendingIntent); //set repeating every 24 hours

关于android - android 每天特定时间通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13121719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com