Hello I would need help with notifications on android, I'm with an app that I need to send several notifications during the day, and I only get that if for example send three notifications I get the last, the first and second are ignored, I guess because I'm not doing the PendingIntents well, but I've already looked for many solutions and I really do not.
This is the method that goes into the OnReceive of the class that extends to Broadcast:
public void bigPicture (Context context, Uri alarmSound,Bitmap bitmapArray,CharSequence cs){
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,100,notificationIntent,PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int id = 1;
int idMas = ++id;
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.ic_notify)
.setContentText(cs)
.setSound(alarmSound)
.setColor(context.getResources().getColor(R.color.colorPrimary))
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmapArray));
notificationManager.notify(idMas,mNotifyBuilder.build());
}
And this other code goes into the activity in an onclick:
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(System.currentTimeMillis());
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(System.currentTimeMillis());
Calendar calendar3 = Calendar.getInstance();
calendar3.setTimeInMillis(System.currentTimeMillis());
calendar1.set(Calendar.HOUR_OF_DAY,15);
calendar1.set(java.util.Calendar.MINUTE,48);
calendar1.set(java.util.Calendar.SECOND,0);
calendar2.set(Calendar.HOUR_OF_DAY,15);
calendar2.set(java.util.Calendar.MINUTE,48);
calendar2.set(java.util.Calendar.SECOND,30);
calendar3.set(Calendar.HOUR_OF_DAY,15);
calendar3.set(java.util.Calendar.MINUTE,49);
calendar3.set(java.util.Calendar.SECOND,00);
int uniqueInt = new Random().nextInt(543254);
Intent intent1 = new Intent(Notificaciones_Activity.this,AlarmReceiver.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setAction(Long.toString(System.currentTimeMillis()));
PendingIntent pendingIntent1 = PendingIntent.getBroadcast(Notificaciones_Activity.this,uniqueInt
,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(Notificaciones_Activity.this,uniqueInt
,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent3 = PendingIntent.getBroadcast(Notificaciones_Activity.this,uniqueInt
,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager1 = (AlarmManager) getSystemService(ALARM_SERVICE);
AlarmManager alarmManager2 = (AlarmManager) getSystemService(ALARM_SERVICE);
AlarmManager alarmManager3 = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP,calendar1.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent1);
alarmManager2.setRepeating(AlarmManager.RTC_WAKEUP,calendar2.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent2);
alarmManager3.setRepeating(AlarmManager.RTC_WAKEUP,calendar3.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent3);
If instead of setting setReapeating () I set setExact () if it works, but they jump
old notifications out of time.
I hope your help, thank you.