【问题标题】:update Forground notification from Activity从 Activity 更新前台通知
【发布时间】:2016-06-30 01:16:14
【问题描述】:

我在服务的 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);

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多