gpt4 book ai didi

android - 设置通知提醒

转载 作者:行者123 更新时间:2023-11-30 04:27:14 24 4
gpt4 key购买 nike

嗨,我是 android 新手..我开发了一个程序来设置特定时间的通知但问题是它只显示 2011 年 10 月之前的通知如果我输入 11 月的任何日期,它不会显示任何通知..看起来很奇怪,但真的卡在这里....

主要 Activity ..

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Calendar cal = Calendar.getInstance(); // for using this you need to

cal.set(Calendar.MONTH, 11);
cal.set(Calendar.YEAR, 2011);
cal.set(Calendar.DAY_OF_MONTH, 25);
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 28);

Intent alarmintent = new Intent(getApplicationContext(),
AlarmReceiver.class);
alarmintent.putExtra("title", "Title of our Notification");
alarmintent.putExtra("note", "Description of our Notification");


int HELLO_ID = 1;
PendingIntent sender = PendingIntent.getBroadcast(
getApplicationContext(), HELLO_ID, alarmintent,
PendingIntent.FLAG_UPDATE_CURRENT |
Intent.FILL_IN_DATA);

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
}

和警报接收器 Activity ...

public class AlarmReceiver extends BroadcastReceiver {

private static final String NotificationManager = null;
private static int NOTIFICATION_ID = 0;

@Override
public void onReceive(Context context, Intent intent) {

(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager manger = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"Combi Note", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID, new Intent(context,
AlarmReceiver.class), 0);
Bundle extras = intent.getExtras();
String title = extras.getString("title");

String note = extras.getString("note");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;

manger.notify(NOTIFICATION_ID, notification);

}
};

最佳答案

Calendar.set(Calendar.MONTH, month)

需要一个从 0 开始的值。 11 是十二月。

关于android - 设置通知提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270032/

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