amanda45
amanda45

Reputation: 595

update Forground notification from Activity

I set up a foreground notification in my service's OnstartCommand() How can I Update the Text in the Notification from my MainActivity?

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);

Upvotes: 0

Views: 65

Answers (1)

Klojure
Klojure

Reputation: 11

Use the same notificationId to send a new notification in the MainActivity.

Upvotes: 1

Related Questions