0

Les variables dans BroadcastReceiver ne sont pas mises à jour chaque fois que je mets un gestionnaire de notification/alarme.Comment mettre à jour le récepteur de radiodiffusion. (notification multiple)

enter image description here

enter image description here

"récepteur (recyclage)" est à partir d'un fragment.

récepteur

» est d'une classe de BroadcastReceiver.

onCreateView

intentAlarmManager = new Intent(context, NotificationReceiver.class); 
pendingIntent = PendingIntent.getBroadcast(context, 0, intentAlarmManager, PendingIntent.FLAG_UPDATE_CURRENT); 

méthode de notification

private void setNotification(int hour, int min, int interval, int uniqueID) { 

    //get instance of the calendar 
    calendar = Calendar.getInstance(); 
    calendar.set(Calendar.HOUR_OF_DAY, hour); 
    calendar.set(Calendar.MINUTE, min); 
    //create delayed intent 
    pendingIntent = PendingIntent.getBroadcast(context, uniqueID, intentAlarmManager, PendingIntent.FLAG_UPDATE_CURRENT); 
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * (interval * 30), pendingIntent); 


} 

Recycleur son attaché à un auditeur de commutation

setNotification(Integer.parseInt(model.getHour()), Integer.parseInt(model.getMinute()), Integer.parseInt(model.getInterval()), Integer.parseInt(model.getTime())); 

Récepteur

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
Intent intentToStartWhenAlarmSets = new Intent(context, LoginActivity.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intentToStartWhenAlarmSets, PendingIntent.FLAG_UPDATE_CURRENT); 

     NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
       .setContentIntent(pendingIntent) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle("Content Title") 
       .setContentText("Notify " + HomeFragment.notifMedName) 
       .setSound(notifSound) 
       .setVibrate(pattern) 
       //swipable 
       .setAutoCancel(true); 
     Log.d(ContentValues.TAG, "receiver " + HomeFragment.notifMedName); 

     notificationManager.notify((int) System.currentTimeMillis(), builder.build()); 

Répondre

0

Je l'ai compris, je pense. Bien que je ne sois pas sûr que ce soit le meilleur/correct moyen (je travaille cependant).

Donc dans ma classe de récepteur i ajouté

intent.getStringExtra("string); 

et dans mon fragment i ajouté

intentAlarmManager.putExtra("string", notifMedName); 
getActivity().sendBroadcast(intentAlarmManager); 

et aussi je changé toute intention en attente context-getActivity().

N'hésitez pas à répondre si vous avez une meilleure solution.

More info here.