Android 在通知单击时处理推送通知有效负载数据

Android 在通知单击时处理推送通知有效负载数据,android,push-notification,Android,Push Notification,单击通知的要求:我希望在单击通知时处理(执行)IntentReceiver.java类,然后转发意图 IntentReceiver.java(BroadcastReceiver的子类)--->Notification.java(活动)--->主仪表板(活动) 1.)在我的应用程序中,我有一个单独的类“IntentReceiver.java”,它是“BroadcastReceiver”的子类 2.)之后,在我的“IntentReceiver.java”类中,我切换到“Notification.ja

单击通知的要求:我希望在单击通知时处理(执行)IntentReceiver.java类,然后转发意图

IntentReceiver.java(BroadcastReceiver的子类)--->Notification.java(活动)--->主仪表板(活动)

1.)在我的应用程序中,我有一个单独的类“IntentReceiver.java”,它是“BroadcastReceiver”的子类

2.)之后,在我的“IntentReceiver.java”类中,我切换到“Notification.java”类,该类没有 布局屏幕,操作一些数据并切换到主仪表板

3.)在此主仪表板上,我将代表接收到的不同键处理不同的对话(通过putExtra() 操作后,从“Notification.java”类在主仪表板上

IntentReceiver.java类的代码:这是一个单独的类,用于处理每个通知

public class IntentReceiver extends BroadcastReceiver {
        Context ctx;

        private static String PUSH_KEY_ALERT = "alert";

   @Override

        public void onReceive(Context context, Intent intent) {

            this.ctx = context;

        String alert = intent.getStringExtra(PUSH_KEY_ALERT);

        Bundle extras = getResultExtras(true);

        extras.putInt(PushIOManager.PUSH_STATUS, PushIOManager.PUSH_HANDLED_NOTIFICATION);

        setResultExtras(extras);

    }

}
清单配置:

<receiver android:name="com.DxS.android.push.IntentReceiver" > </receiver>



<activity android:name=".Notification">

        <action android:name="com.DxS.android.NOTIFICATIONPRESSED" />

        <category android:name="android.intent.category.DEFAULT" />

 </activity>



 <activity android:name=".dashboard"> </activity>

这是我的要求流程,请您提供一个最好的方法来做到这一点。
提前感谢…

首先,您的
onReceive
方法应该检查错误。 点击通知时,以下代码将显示通知并启动
通知
活动。如果没有布局,我不确定通知活动的目的是什么。也许它不一定是一个活动,点击通知应该直接启动
仪表板
活动

public class IntentReceiver extends BroadcastReceiver {
   static final String TAG = "IntentReceiver";
   Context ctx;

   @Override
   public void onReceive(Context context, Intent intent) {
       GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
       ctx = context;
       String messageType = gcm.getMessageType(intent);
       if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) 
           Log.i(TAG, "PUSH RECEIVED WITH ERROR: " + intent.getExtras().toString());
       else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) 
           Log.i(TAG, "DELETED PUSH MESSAGE: " + intent.getExtras().toString());
       else
       {
           Log.i(TAG, "Received PUSH: " + intent.getExtras().toString());
           postNotification(intent.getExtras());
       }
       setResultCode(Activity.RESULT_OK);
   }

  // post GCM message to notification center.
  private void postNotification(Bundle data) {
     String msg = data.getString("alert");
     Log.i(TAG, "message: " + msg);

     Intent intent = new Intent(ctx, Notification.class);
     PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, 0);

     NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
     .setContentTitle("Your Title")
     .setContentText(msg)
     .setTicker(msg)
     .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
     .setAutoCancel(true)
     .setOnlyAlertOnce(true)
     .setDefaults(Notification.DEFAULT_VIBRATE); 

     builder.setContentIntent(contentIntent);
     NotificationManager notificationManager = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
     notificationManager.notify(0, builder.build());
  }
}