1

カスタム プッシュ ブロードキャスト レシーバーから [こちら][1] で指定されたアクティビティにバンドルを送信しています。

これは、エクストラでインテントを起動するようにコードを変更した方法です。

    Intent launchIntent  = new Intent(context, Home2Activity.class);
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    //Put push notifications payload in Intent
    launchIntent.putExtras(pushBundle);
    launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString());
    context.startActivity(launchIntent);

通常のレシーバーは正常に動作しており、onNewIntent を正しく起動していますが、カスタム レシーバーは null エクストラを表示しています。

4

1 に答える 1

1

問題はフラグにありました。私はそれを自分で考え出しました。以下に示すように、pushwoosh ドキュメントのカスタム プッシュ ブロードキャスト レシーバーを変更して、エクストラを取得します。

    public class NotificationReceiver extends BroadcastReceiver

{
    public void onReceive(Context context, Intent intent)
    {
        if (intent == null)
            return;

        //Let Pushwoosh SDK to pre-handling push (Pushwoosh track stats, opens rich pages, etc.).
        //It will return Bundle with a push notification data
        Bundle pushBundle = PushManagerImpl.preHandlePush(context, intent);
        if(pushBundle == null)
            return;

        //get push bundle as JSON object
        JSONObject dataObject = PushManagerImpl.bundleToJSON(pushBundle);
        Log.d("APIPushwoosh", dataObject.toString());
        //Get default launcher intent for clarity
        //Intent launchIntent  = new Intent(context, Home2Activity.class);


        Intent launchIntent= new Intent();
        launchIntent.setClass(context, Home2Activity.class);
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED| Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //Put push notifications payload in Intent
        //launchIntent.putExtras(pushBundle);
        launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString());
        //GlobalConst.setPush(dataObject.toString());
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        try {
            contentIntent.send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }

        //Start activity!
        //context.startActivity(launchIntent);

        //Let Pushwoosh SDK post-handle push (track stats, etc.)
        PushManagerImpl.postHandlePush(context, intent);
    }

このリンクに感謝します。

于 2016-02-05T07:51:58.143 に答える