¿Qué debo hacer para que cuando mi aplicación mande una segunda (tercera..cuarta... etc) notificación no se sustituya y se vayan incluyendo todas?
MainActivity.java:
public class MainActivity extends ActionBarActivity {
DatePicker datePicker;
TimePicker timePicker;
Button btnStart;
Uri uriAlarm;
final static int RQS_1 = 1;
EditText textonombre;
EditText textodescripcion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notif_main);
datePicker = (DatePicker)findViewById(R.id.datepicker);
timePicker = (TimePicker)findViewById(R.id.timepicker);
btnStart = (Button)findViewById(R.id.start);
uriAlarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
textonombre = (EditText)findViewById(R.id.textonombre);
textodescripcion = (EditText)findViewById(R.id.textodescripcion);
btnStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setAlarm(uriAlarm);
Toast.makeText(MainActivity.this, "Alarma ACTIVADA", Toast.LENGTH_SHORT).show();
}
});
}
private void setAlarm(Uri passuri){
Calendar cal = Calendar.getInstance();
cal.set(datePicker.getYear(),
datePicker.getMonth(),
datePicker.getDayOfMonth(),
timePicker.getCurrentHour(),
timePicker.getCurrentMinute(),
00);
Intent intent = new Intent(getBaseContext(), pruebaintento.dos.notif.AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
getBaseContext(),
RQS_1,
intent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
}
}
AlarmReceiver.java
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(context,MainActivity.class);
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,id,repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("NOMBRE")
.setContentText("DESCRIPCIÓN")
.setAutoCancel(true);
notificationManager.notify(id,builder.build());
}
}
Edito: @Elenasys
public class AlarmReceiver extends BroadcastReceiver {
int id= 1;
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(context,MainActivity.class);
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,id++,repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("NOMBRE")
.setContentText("DESCRIPCIÓN")
.setAutoCancel(true);
notificationManager.notify(id++,builder.build());
}
}