Facebook SDK 3.0 Integration

Hi,

After you complete java call in onComplete means in listener you call the native method to passback values that native method will store that value in static format for you can store in user-default.
for java native calling you find on internet, you can refere this http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/
may be you are getting null-pointer due to data-conversion from c++ to java http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp276
so string passing,

void CCApplication::openURL(char *msg){

JniMethodInfo minfo;

if(JniHelper::getStaticMethodInfo(minfo,
“org/cocos2dx/lib/Cocos2dxHelper”,
“openURL”,
“(Ljava/lang/String;)V”))
{
jstring StringArg1 = minfo.env~~>NewStringUTF;
minfo.env~~>CallStaticVoidMethod(minfo.classID, minfo.methodID, StringArg1);
minfo.env~~>DeleteLocalRef;
minfo.env~~>DeleteLocalRef(minfo.classID);
}
in cocos2dxHelper method you will get string in agrs,
public static void openURL(String url) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
me.startActivity(i);
}
}

just try this, then may you can modified it later.

Thank you.

This is the function I have written java :

`public void invokeNativeCode() {
int sum = nativeAdd(1, 2);
Log.i(“native”, "sum is " + sum);
}

private native int nativeAdd(int a, int b);`

just for testing. In my HelloWorldScene.h, I have put this :

`#ifdef __cplusplus
extern “C” {
#endif

jint Java_com_WBS_Test0001_Test0001_nativeAdd(JNIEnv *env, jobject thiz, jint a, jint b)
{
printf(“inside c++ function!!!”);
return a + b;
}

#ifdef __cplusplus
}
#endif`

but I am getting error in saying “multiple definition of `Java_com_WBS_Test0001_Test0001_nativeAdd’”

Fixed it. If i move all the code to the cpp file then it works :slight_smile:

In main.cpp we can access functions CCDirector and CCApplication like this :

`void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
if (!CCDirector::sharedDirector()->getOpenGLView())
{
CCEGLView *view = CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h);

    AppDelegate *pAppDelegate = new AppDelegate();
    CCApplication::sharedApplication()->run();
}
else
{
    ccDrawInit();
    ccGLInvalidateStateCache();

    CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
    CCTextureCache::reloadAllTextures();
    CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
    CCDirector::sharedDirector()->setGLDefaultValues(); 
}

}`

Im trying to do the same in my code as follows :

`void Java_com_WBS_Test0001_Test0001_nativeFbUserName(JNIEnv *env, jobject thiz,
jstring name, jint len) {
CCLog(“inside c++ function!!!”);
char username = const_cast<char> (env->GetStringUTFChars(name, NULL));
CCLog(“name is %s”, username);
CCImage *ccimg = new CCImage();

ccimg->initWithImageData(username, (int) len,
        (cocos2d::CCImage::EImageFormat) 3, 200, 200, 8);
CCTexture2D *tex = new CCTexture2D();
tex->initWithImage(ccimg);
CCSprite *sprite = CCSprite::createWithTexture(tex);
sprite->setPosition(ccp(300, 200));
HelloWorld::getShared()->addChild(sprite);

}`

Im trying to access an instance of HelloWorld via a static function. The function is defined in the header file as
@ static HelloWorld* getShared();@

and the corresponding code in the cpp file is
`static HelloWorld *_sharedInstance;

HelloWorld* getShared() {
return _sharedInstance;
}`

The error that I get when i try to build the project is “Undefined Reference to ‘HelloWorld::getShared()’”,

Any ideas on what is wrong?