1

我有一个关于推送通知的问题,我可以处理发送消息并在 textview 中显示它。但在那之后我发送了第二次推送并尝试打开它,它仍然显示上一个推送通知的消息。

我该如何解决?

这是代码句柄消息

  package com.example.cepyolwebview;

    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;

    import com.xtify.sdk.api.XtifyBroadcastReceiver;
    import com.xtify.sdk.api.XtifySDK;

    public class XtifyNotifier extends XtifyBroadcastReceiver {
        String TAG = XtifyNotifier.class.getName();
        private static final String NOTIFICATION_TITLE = "com.xtify.sdk.NOTIFICATION_TITLE";
        private static final String NOTIFICATION_CONTENT = "com.xtify.sdk.NOTIFICATION_CONTENT";

        @Override
        public void onMessage(Context context, Bundle msgExtras) {
            Log.d(TAG, "-- Notification recived");
            String title = msgExtras.getString(NOTIFICATION_TITLE);
            String message = msgExtras.getString(NOTIFICATION_CONTENT);
            Log.d(TAG, "Notification Title: " + title);
            Log.d(TAG, "Notification Content: " + message);
            generateNotification(context, title, message);

        }

        @Override
        public void onRegistered(Context context) {
            Log.d(TAG, "-- SDK registerd");
            Log.d(TAG, "XID is: " + XtifySDK.getXidKey(context));
        }

        @Override
        public void onC2dmError(Context context, String errorId) {
            Log.i(TAG, "ErrorId: " + errorId);
        }

        private static void generateNotification(Context context, String title,
                String message) {
            int icon = R.drawable.ic_launcher;

            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(icon, title,
                    System.currentTimeMillis());

            Intent notificationIntent = new Intent(context, Utils.class);
            // set intent so it does not start a new activity
            notificationIntent.putExtra("message", message);
            notificationIntent.putExtra("title", title);

            PendingIntent intent = PendingIntent.getActivity(context, 0,
                    notificationIntent, 0);
            notification.setLatestEventInfo(context, title, message, intent);
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(0, notification);
        }
  }

和查看通知的代码

package com.example.cepyolwebview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Utils extends Activity {

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.utils);
        TextView title= (TextView) findViewById(R.id.title);
        TextView message= (TextView) findViewById(R.id.message);

        title.setText(getIntent().getExtras().getString("title"));
        message.setText(getIntent().getExtras().getString("message"));


    }
}
4

1 回答 1

1

用这个。

 PendingIntent intent=PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT );
于 2012-09-05T12:53:34.513 回答