我想制作一个应用程序,让用户决定每天什么时候希望他通过通知提醒某些事情......
我想知道我应该如何在用户希望早上 7:00 前的特定时间触发通知,并让他点击通知并在特定活动中输入应用程序。但是,当用户不想再收到任何通知(单击按钮)时,我如何取消所有通知...?
我做了类似的东西
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);
但没有运气...
请问有什么帮助吗?