I want to pass information from a push notification with custom payload into the cocos2dx user defaults.
On iOS i only have to do the following on the AppController.mm:
std::string payload_string([payload UTF8String]);
cocos2d::UserDefault::getInstance()->setStringForKey("notification_payload", payload_string);
and since its cpp code it works just like this.
My question is, how do you do this for the android side?
I get the information like this on the Cococ2dxActivity.java:
String payload = getIntent().getStringExtra("com.tapjoy.PUSH_PAYLOAD");
if (payload != null) {
Log.d("Tapjoy", "Tapjoy push notification with payload: " + payload);
// cocos2d::UserDefault::getInstance()->setStringForKey("notification_payload", payload); // This won't work on java.
}
1 Like
Still haven’t found how to achieve this. Anyone has any ideas?
i__d__k
February 18, 2016, 4:58am
#3
If you've read [Part 1. Calling Java functions from C++ in cocos2d-x](./call-java-functions-from-cpp.html), you'll agree with me that the task is not as hard as it seems. Fortunately, the other way around, i.e., calling C++ functions from Java, is...
This might help.
I was looking for other questions similar to mine and i found this:
Hello,
On iOS, I can save UserDefault data like this:
// AppController.mm file
cocos2d::UserDefault::getInstance()->setStringForKey("value", 1);
How can I do the same from Android (Application.java file, for example)?
Thank you very much.
I think he wanted to achieve the same as i do but they misunderstand him.
The issue is quite simple:
On iOS you can save to the “cocos2d::UserDefault” from the AppController because it can execute cpp code.
But i want to call the same cocos2d function from the “java app controller” (Cococ2dxActivity.java), whats the equivalent for it on java? (that uses the cocos2dxHelper maybe?)