0

Ich eingerichtet eine Vordergrundbenachrichtigung in meinem Dienst OnstartCommand() Wie kann ich den Text in der Benachrichtigung von meinem MainActivity aktualisieren?Update Forground-Benachrichtigung von Aktivität

Intent notificationIntent = new Intent(this, MainActivity.class); 
     notificationIntent.setAction("new"); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 
       notificationIntent, 0); 
     Bitmap icon = BitmapFactory.decodeResource(getResources(), 
       R.drawable.ic_launcher); 
     // builder = new NotificationCompat.Builder(this); 

     notification = new NotificationCompat.Builder(this) 
       .setContentTitle("Test") 
       .setTicker("Test") 
       .setContentText("Update This") 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)) 
       .setContentIntent(pendingIntent) 
       .setOngoing(true).build(); 
     startForeground(101, notification); 

Antwort

1

Verwenden Sie dieselbe notificationId, um eine neue Benachrichtigung in der MainActivity zu senden.