Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

data payload is not always available in the Intent extras #156

Closed
RoelBlomjousDevelopment opened this issue Jan 14, 2016 · 1 comment
Closed

Comments

@RoelBlomjousDevelopment

When using the option "Hybrid messages with both notification and data payload"
Data payload is not added to the intent extras when it is received via onNewIntent using launchMode is set to singleTop

Using the following test message

  {
    "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "my icon",
      "click_action" : "OPEN_ACTIVITY_1"
    },
    "data" : {
      "date" : "$(date)",
    }
  }

AndroidManifest.xml

...
        <activity
            android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
            android:name="com.my.appNameTest.testActivity"
            android:label="@string/app_name"
            android:screenOrientation="unspecified"
            android:launchMode="singleTop">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <intent-filter>
                <action android:name="OPEN_ACTIVITY_1"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
...

The data payload is available in the intent extras when the intent is accessed via the onCreate. But it is missing when the Intent is received via onNewIntent.

/test: onNewIntent
/test: Intent { act=OPEN_ACTIVITY_1 flg=0x10400000 pkg=com.my.appName cmp=com.my.appName/com.my.appNameTest.testActivity (has extras) }
/test: Bundle[mParcelledData.dataSize=216
/test: onResume
/test: Intent { act=OPEN_ACTIVITY_1 flg=0x10400000 pkg=com.my.appName cmp=com.my.appName/com.my.appNameTest.testActivity (has extras) }
/test: Bundle[mParcelledData.dataSize=216
/test: onCreate
/test: Intent { act=OPEN_ACTIVITY_1 flg=0x10000000 pkg=com.rbd.aqvMobile cmp=com.my.appName/com.my.appNameTest.testActivity (has extras) }
/test: Bundle[{date=Fri Jan 15 00:37:39 CET 2016, from=***********}]

The above log was generated using

    private void logIntent(Intent intent)
    {
        Log.d(TAG, intent.toString());
        Bundle extras = intent.getExtras();
        if (null != extras) {
            Log.d(TAG, extras.toString());
        }
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        logIntent(getIntent());
    }
    @Override
    protected void onResume()
    {
        Log.d(TAG, "onResume");
        logIntent(getIntent());
        super.onResume();
    }
    @Override
    protected void onNewIntent(Intent intent) {
        Log.d(TAG, "onNewIntent");
        logIntent(intent);
        super.onNewIntent(intent);
        setIntent(intent);
    }

version used: gcm 8.3.0

@morepork
Copy link

It looks like the data is there, it is just parcelled. If you try to get a particular key/value it should show up. You can always do something like intent.getStringExtra("date") before logging the Intent to force its data to unparcel.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants