更新活动的Forground通知

时间:2016-06-30 01:16:15

标签: android android-activity android-service android-notifications

我在我的服务中设置了前台通知的OnstartCommand()如何从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);

1 个答案:

答案 0 :(得分:1)

使用相同的notificationId在MainActivity中发送新通知。

相关问题