Android 如何更新通知?

Android 如何更新通知?,android,notifications,broadcast,Android,Notifications,Broadcast,我有一个带有文本视图和按钮的自定义通知。我想在单击按钮时更改TextView的文本。 我做了一个广播,当按钮点击程序开始运行该广播时,广播的代码是: package com.mori.sepid.notifications; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; i

我有一个带有文本视图和按钮的自定义通知。我想在单击按钮时更改
TextView
的文本。 我做了一个广播,当按钮点击程序开始运行该广播时,广播的代码是:

package com.mori.sepid.notifications;

 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
 import android.view.ViewGroup;
 import android.app.Notification;
 import android.widget.RemoteViews;
 import android.app.NotificationManager;
 import android.widget.TextView;

 public class button_broadcast_resiver extends BroadcastReceiver {
   public button_broadcast_resiver() {
   }

    @Override
    public void onReceive(Context context, Intent intent) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.customnoti1);
        remoteViews.setTextViewText(R.id.text,"Hi morteza");
        NotificationManager noti=
        (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);

    }


}

正如上面的代码所示,我从RemoteView创建了一个对象,并将所选文本放入TextView,但我不知道如何将此更改更新到通知面板。

下面的代码解释了如何创建您自己的通知:

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    final Notification notification = new NotificationCompat.Builder(context)
            //here you set icon which will be displayed on top bar
            .setSmallIcon(R.drawable.your_ic_notification)
            //here is title for your notification
            .setContentTitle("tite"/*your notification title*/)
            //here is a content which will be displayed when someone expand action bar
            .setContentText("Some example context string"/*notifcation message*/)
            .build();
    notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(1000/*some int notification id*/, notification);
此外,如果要添加远程视图,可以使用以下方法:

setContent(RemoteViews remoteView)

Notification.Builder
class

中,您只需使用相同的notificationID发布新通知