I had the same problem. The workaround I found is to generate the json we create and add all json as a pair of key values โโin the data object that we send to the gcm cloud server -
Usually we ship -
myData: { 'title' : 'New Notification', 'myAge' : 25 } json: { 'to': to, 'data': myData }
Thus, all values โโinside the data packet are converted to String. In the above data, 25 is converted to String.
How am i doing this -
json: { 'to': to, 'data': {'myData' : myData} }
Now 25 will remain intact.
Note Stroke the myData JsonObject before submitting it. In Javascript, I use JSON.stringify(myData);
Then at the end of Android we can get all json -
@Override public void onMessageReceived(String from, Bundle data) { try { JSONObject myData = new JSONObject(data.getString("myData")); } catch (JSONException e){} }
Now all the resulting values โโwill be in their original types.
source share