connect cocos2dx to facebook in android

Hi,

I’m trying to connect my cocos2dx android appliacation to facebook.
For that I use JNI and it works fine.

My problem is that I want to get a notnification when the facebook request is complete.
I want to send a a pointer to delegate function in cpp so the java part will call it when the request complete.

For example, in the login method (I chose to ask about the login but I want the same behavior for every method I use):

I have a cpp method, UserDidLogin() which I want to be called after user had logged in.

The java code should be something like that :

public static void login2Facebook()
{
Session.openActiveSession(me, true, new Session.StatusCallback()
{

// callback when session changes state
Override public void call(Session session, SessionState state, Exception exception) { mSession = session; if (session.isOpened()) { Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { // callback after Graph API response with user objectOverride
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
userInfo = user;
// *HERE I WANT TO CALL THE native UserDidLogin()*
}
}
});
}
}
});
}

The current JNI call is:

void CCAndroidApplication::login2Facebook()
{

JniMethodInfo minfo;

if(JniHelper::getStaticMethodInfo(minfo,
“org/cocos2dx/example/myandroidtest”,
“login2Facebook”,
“()V”))
{
minfo.env~~>CallStaticVoidMethod;
minfo.env~~>DeleteLocalRef(minfo.classID);
}
}

Does anybody know how should I cahnge my code in order to achieve my goal?

Thanks

I have that problem.

Sarit Cohen wrote:

Hi,
>
I’m trying to connect my cocos2dx android appliacation to facebook.
For that I use JNI and it works fine.
>
My problem is that I want to get a notnification when the facebook request is complete.
I want to send a a pointer to delegate function in cpp so the java part will call it when the request complete.
>
For example, in the login method (I chose to ask about the login but I want the same behavior for every method I use):
>
I have a cpp method, UserDidLogin() which I want to be called after user had logged in.
>
The java code should be something like that :
>
public static void login2Facebook()
{
Session.openActiveSession(me, true, new Session.StatusCallback()
{
>
// callback when session changes state
Override public void call(Session session, SessionState state, Exception exception) { mSession = session; if (session.isOpened()) { Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { // callback after Graph API response with user objectOverride
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
userInfo = user;
// *HERE I WANT TO CALL THE native UserDidLogin()*
}
}
});
}
}
});
}
>
The current JNI call is:
>
void CCAndroidApplication::login2Facebook()
{
>
JniMethodInfo minfo;
>
if(JniHelper::getStaticMethodInfo(minfo,
“org/cocos2dx/example/myandroidtest”,
“login2Facebook”,
“()V”))
{
minfo.env~~>CallStaticVoidMethod;
minfo.env~~>DeleteLocalRef(minfo.classID);
}
}
>
Does anybody know how should I cahnge my code in order to achieve my goal?
>
Thanks

I’m having same problem and looking for a solution last few days… what I found is that you can’t call a native method from a static method.
Also I’m having problems trying to call a non-static method using JniHelper (is that really possible? GetMethodInfo works but CallXXXMethod crashes, maybe I’m using it in wrong way…. but static works so I don’t know)
(Maybe something about take a reference to the instance instead a reference to the class?)

For the problem you have about how to call the native function you can take a look at: [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_jni#1-Java-code-invoke-c-code]]