알림 일시 중지 옵션을 사용하여 알림 응용 프로그램을 만들었습니다. 알림이 한 번만 울리면 알림이 모두 활성화됩니다. 두 번째 알림을 추가하면 첫 번째 알림이 두 번째 (중복) 하나 .. 여기 코드를 보았습니다. Plz은Android 알림에서 문제가 발생했습니다.
public void onReceive(Context context, Intent intent) {
mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence name = intent.getStringExtra("Name");
CharSequence desc = intent.getStringExtra("Description");
notificationCount = Integer.parseInt(intent.getExtras().get("NotifyCount")
.toString());
sound = new Sound(context);
sound.play();
Intent notifyIntent = new Intent(context, ReminderPopup.class);
notifyIntent.putExtra("Name", name);
notifyIntent.putExtra("Description", desc);
notifyIntent.putExtra("NotifyCount", notificationCount);
PendingIntent contentIntent = PendingIntent.getActivity(context, notificationCount,
notifyIntent, 0);
notification = new Notification(R.drawable.ic_launcher, "Notification",
System.currentTimeMillis());
notification.setLatestEventInfo(context, name, desc, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(
Integer.parseInt(intent.getExtras().get("NotifyCount")
.toString()), notification);
ReminderPopup.java
public void onClick(DialogInterface dialog, int which) {
if (minute != 0) {
cal = Calendar.getInstance();
mYear = cal.get(Calendar.YEAR);
mMonth = cal.get(Calendar.MONTH) + 1;
mDay = cal.get(Calendar.DATE);
mHour = cal.get(Calendar.HOUR_OF_DAY);
mMinute = cal.get(Calendar.MINUTE);
snooze = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + (mMinute + minute);
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(snooze);
} catch (ParseException e) {
e.printStackTrace();
} catch (java.text.ParseException e) {
e.printStackTrace();
}
when = dt.getTime();
AlarmManager mgr = (AlarmManager) getApplicationContext()
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(
getApplicationContext(), ReminderAlarm.class);
notificationIntent.putExtra("Name", name);
notificationIntent.putExtra("Description", desc);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(
getApplicationContext(), notificationCount,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(getApplicationContext(),
name +" Reminder Snoozed for " + minute + " Minutes " + notificationCount,
Toast.LENGTH_LONG).show();
}
012에게
reminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();
contentSnooze = snoozeEdit.getText().toString();
ContentValues details = new ContentValues();
details.put("Name", contentTitle);
details.put("Description", contentText);
details.put("SnoozeTime", contentSnooze);
db.insert("snoozetable", null, details);
Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();
if (dateFlag == true && timeFlag == true) {
notificationCount = notificationCount + 1;
dateFlag = false;
timeFlag = false;
time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + mMinute;
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long when = dt.getTime();
/*contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();*/
AlarmManager mgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(mContext,
ReminderAlarm.class);
notificationIntent.putExtra("Name", contentTitle);
notificationIntent.putExtra("Description", contentText);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(mContext,
notificationCount, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
Toast.LENGTH_LONG).show();
contentTitle = "";
contentText = "";
descEdit.setText("");
snoozeEdit.setText("");
}
reminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();
contentSnooze = snoozeEdit.getText().toString();
ContentValues details = new ContentValues();
details.put("Name", contentTitle);
details.put("Description", contentText);
details.put("SnoozeTime", contentSnooze);
db.insert("snoozetable", null, details);
Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();
if (dateFlag == true && timeFlag == true) {
notificationCount = notificationCount + 1;
dateFlag = false;
timeFlag = false;
time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + mMinute;
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long when = dt.getTime();
/*contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();*/
AlarmManager mgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(mContext,
ReminderAlarm.class);
notificationIntent.putExtra("Name", contentTitle);
notificationIntent.putExtra("Description", contentText);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(mContext,
notificationCount, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
Toast.LENGTH_LONG).show();
contentTitle = "";
contentText = "";
descEdit.setText("");
snoozeEdit.setText("");
}
reminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();
contentSnooze = snoozeEdit.getText().toString();
ContentValues details = new ContentValues();
details.put("Name", contentTitle);
details.put("Description", contentText);
details.put("SnoozeTime", contentSnooze);
db.insert("snoozetable", null, details);
Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();
if (dateFlag == true && timeFlag == true) {
notificationCount = notificationCount + 1;
dateFlag = false;
timeFlag = false;
time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + mMinute;
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long when = dt.getTime();
/*contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();*/
AlarmManager mgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(mContext,
ReminderAlarm.class);
notificationIntent.putExtra("Name", contentTitle);
notificationIntent.putExtra("Description", contentText);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(mContext,
notificationCount, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
Toast.LENGTH_LONG).show();
contentTitle = "";
contentText = "";
descEdit.setText("");
snoozeEdit.setText("");
}
reminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();
contentSnooze = snoozeEdit.getText().toString();
ContentValues details = new ContentValues();
details.put("Name", contentTitle);
details.put("Description", contentText);
details.put("SnoozeTime", contentSnooze);
db.insert("snoozetable", null, details);
Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();
if (dateFlag == true && timeFlag == true) {
notificationCount = notificationCount + 1;
dateFlag = false;
timeFlag = false;
time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + mMinute;
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long when = dt.getTime();
/*contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();*/
AlarmManager mgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(mContext,
ReminderAlarm.class);
notificationIntent.putExtra("Name", contentTitle);
notificationIntent.putExtra("Description", contentText);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(mContext,
notificationCount, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
Toast.LENGTH_LONG).show();
contentTitle = "";
contentText = "";
descEdit.setText("");
snoozeEdit.setText("");
}
ReminderActivity.java
reminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
contentTitle = nameEdit.getText().toString();
contentText = descEdit.getText().toString();
contentSnooze = snoozeEdit.getText().toString();
time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
+ "-" + mMinute;
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd hh-mm");
Date dt = null;
try {
dt = df.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long when = dt.getTime();
AlarmManager mgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent(mContext,
ReminderAlarm.class);
notificationIntent.putExtra("Name", contentTitle);
notificationIntent.putExtra("Description", contentText);
notificationIntent.putExtra("NotifyCount",
notificationCount);
PendingIntent pi = PendingIntent.getBroadcast(mContext,
notificationCount, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
Toast.LENGTH_LONG).show();
}
ReminderAlarm.java .. 도와주세요
PendingIntent.FLAG_UPDATE_CURRENT); 이로 인해이 문제가 발생합니다. 기존의 새로운 보류 중을 업데이트합니다. –
Mr.Tamilselvan에게 감사드립니다. 그게 내가 처음에 생각했던 것. 그러나 나중에 나는 그것을 발견했다. 나는 대답을 여기에 게시한다. – Raja45
; k @ user2211247 –