How to access UserDefaults from JNIResults.cpp?

  • Sonared
    Likes 0

    Problem Description

    I’ve implemented AdColony successfully both in iOS and Android.

     

    For iOS, I understood that 

     

         UserDefault::getInstance()->setStringForKey(), etc

     

    uses NSUserDefaults. So I can access the same userdefaults from Objective-C as well from IOSResults.mm in:

        +( void )videoWasViewedAdcolony:( BOOL )result {}

     

    How can I do the same in Android side? in JNIResults.cpp,

         JNIEXPORT void JNICALL Java_sonar_systems_frameworks_AdColony_AdColonyAds_rewardedVideoWasViewedAdcolony(JNIEnv* env, jobject thiz, jboolean result)

        { 

            //CPP code here

            string current_key = UserDefaults::getInstance()->getStringForKey("AdColony_CurrentKey"); // ← This doesn’t compile.

            CCLOG("VideoAdFinished1 %s", current_key.c_str());

        }

     

    I want to implement this logic:

     

        1) User watches AdColony 

        2) After done watching, Java_sonar_systems_frameworks_AdColony_AdColonyAds_rewardedVideoWasViewedAdcolony is called, and saved some data into UserDefaults

        3) from .cpp, the game knows that the user watched the video by accessing the data in UserDefaults.

     

    I don’t know how to do #2 for Android.

        

  • Sonar Systems admin
    Likes 0

Login to reply