2012-09-05 22 views
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); 
     } 
    } 

和代碼見notificaiton

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


    } 
} 

回答

1

使用此。

PendingIntent intent=PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT); 
+0

感謝您的幫助。是工作。 –

相關問題