Skip to content

Commit

Permalink
Update SDK version to 4.3.0.0 新增通知到达,点击回调两个接口
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaobo committed Apr 10, 2018
1 parent 11e27c2 commit 086ac81
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
43 changes: 39 additions & 4 deletions Android/GTPushBridge.cpp
Expand Up @@ -23,7 +23,7 @@ extern "C"{
#define COUNTOF(x) (sizeof((x)) / sizeof(x)[0])


const char* kGTPushHelperClassName = "org/cocos2dx/cpp/getui/GTPushHelper";
const char* kGTPushHelperClassName = "org/cocos2dx/cpp/org.cocos2dx.org.cocos2dx.cpp.getui/GTPushHelper";

jobject getContext(){
JniMethodInfo t;
Expand Down Expand Up @@ -210,20 +210,26 @@ GTReceiveClientId_callback g_clientId_callback = NULL;
GTReceiveMessageData_callback g_messageData_callback = NULL;
GTReceiveOnlineState g_onlineState_callback = NULL;
GTReceiveCommandResult g_commandResult_callback = NULL;
GTReceiveNotificationArrived_callback g_notificationArrived_callback = NULL;
GTReceiveNotificationClicked_callback g_notificationClicked_callback = NULL;
void * notificationHandler = NULL;

void GTPushBridge::registerNotificationCallback(void *p_handle,
GTReceiveServicePid_callback pid_callback,
GTReceiveClientId_callback clientId_callback,
GTReceiveMessageData_callback messageData_callback,
GTReceiveOnlineState onlineState_callback,
GTReceiveCommandResult commandResult_callback){
GTReceiveCommandResult commandResult_callback,
GTReceiveNotificationArrived_callback notificationArrived_callback,
GTReceiveNotificationArrived_callback notificationClicked_callback){

g_pid_callback = pid_callback;
g_clientId_callback = clientId_callback;
g_messageData_callback = messageData_callback;
g_onlineState_callback = onlineState_callback;
g_commandResult_callback = commandResult_callback;
g_notificationArrived_callback = notificationArrived_callback;
g_notificationClicked_callback = notificationClicked_callback;
notificationHandler = p_handle;

}
Expand All @@ -247,7 +253,7 @@ JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_getui_GTPushHelper_onReceiveClient
}

JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_getui_GTPushHelper_onReceiveMessageData__Ljava_lang_String_2(JNIEnv *env, jclass, jstring message){
const char * notification = NULL;
const char * notification = NULL;
if(message != NULL){
notification = env->GetStringUTFChars(message, JNI_FALSE);
CCLOG("GeTui onReceiveMessageData, message = %s", notification);
Expand All @@ -260,6 +266,35 @@ JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_getui_GTPushHelper_onReceiveMessage
}
}

JNIEXPORT void Java_org_cocos2dx_cpp_getui_GTPushHelper_onNotificationMessageArrived__Ljava_lang_String_2(JNIEnv *env, jclass, jstring message){
const char * notification = NULL;
if (message != NULL) {
notification = env->GetStringUTFChars(message,JNI_FALSE);
CCLOG("GeTui onNotificationArrived, message = %s", notification);
}
if(g_notificationArrived_callback != NULL){
g_notificationArrived_callback(notificationHandler, notification);
}
if(message != NULL){
env->ReleaseStringUTFChars(message, notification);
}

}

JNIEXPORT void Java_org_cocos2dx_cpp_getui_GTPushHelper_onNotificationMessageClicked__Ljava_lang_String_2(JNIEnv *env, jclass, jstring message){
const char * notification = NULL;
if (message != NULL) {
notification = env->GetStringUTFChars(message,JNI_FALSE);
CCLOG("GeTui onNotificationClicked, message = %s", notification);
}
if(g_notificationClicked_callback != NULL){
g_notificationClicked_callback(notificationHandler, notification);
}
if(message != NULL){
env->ReleaseStringUTFChars(message, notification);
}
}

JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_getui_GTPushHelper_onReceiveOnlineState__Z(JNIEnv *env, jclass, jboolean online){
CCLOG("GeTui onReceiveOnlineState, online = %s", online == JNI_TRUE ? "true" : "false" );
if (g_onlineState_callback != NULL) {
Expand All @@ -274,7 +309,7 @@ JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_getui_GTPushHelper_onReceiveCommand
notification = env->GetStringUTFChars(message, JNI_FALSE);
CCLOG("GeTui onReceiveCommandResult, message = %s", notification );
}
if(g_commandResult_callback!=NULL){
if(g_commandResult_callback != NULL){
g_commandResult_callback(notificationHandler, notification);
}
if(message != NULL){
Expand Down
9 changes: 7 additions & 2 deletions Android/GTPushBridge.h
Expand Up @@ -12,9 +12,12 @@ using namespace std;
typedef void (*GTReceiveServicePid_callback)(void *p_handle, int pid);
typedef void (*GTReceiveClientId_callback)(void *p_handle, const char* clientId);
typedef void (*GTReceiveMessageData_callback)(void *p_handle, const char* message);
typedef void (*GTReceiveNotificationArrived_callback)(void *p_handle, const char* message);
typedef void (*GTReceiveNotificationClicked_callback)(void *p_handle, const char* message);
typedef void (*GTReceiveOnlineState)(void *p_handle, bool online);
typedef void (*GTReceiveCommandResult)(void *p_handle, const char* message);


#endif

#define COCOS2D_DEBUG 1
Expand Down Expand Up @@ -103,8 +106,10 @@ class GTPushBridge {
GTReceiveClientId_callback clientId_callback,
GTReceiveMessageData_callback messageData_callback,
GTReceiveOnlineState onlineState_callback,
GTReceiveCommandResult commandResult_callback
);
GTReceiveCommandResult commandResult_callback,
GTReceiveNotificationArrived_callback notificationArrived_callback,
GTReceiveNotificationClicked_callback notificationClickedCallback
);

#endif

Expand Down
5 changes: 4 additions & 1 deletion Android/GTPushHelper.java
@@ -1,7 +1,6 @@
package org.cocos2dx.cpp.getui;

import android.content.Context;
import android.content.res.TypedArray;

import com.igexin.sdk.PushManager;
import com.igexin.sdk.Tag;
Expand All @@ -25,6 +24,10 @@ public class GTPushHelper {

public static native void onReceiveCommandResult(String message);

public static native void onNotificationMessageArrived(String message);

public static native void onNotificationMessageClicked(String message);

public static void init(Context context){
mContext = context;
}
Expand Down
35 changes: 31 additions & 4 deletions Android/GTPushIntentService.java
@@ -1,10 +1,10 @@
package org.cocos2dx.cpp.getui;

import android.content.Context;
import android.util.Log;

import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTNotificationMessage;
import com.igexin.sdk.message.GTTransmitMessage;

import org.json.JSONException;
Expand All @@ -21,9 +21,6 @@

public class GTPushIntentService extends GTIntentService {




@Override
public void onReceiveServicePid(Context context, int pid) {
GTPushHelper.onReceiveServicePid(pid);
Expand Down Expand Up @@ -64,4 +61,34 @@ public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
e.printStackTrace();
}
}

//通知到达
@Override
public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("messageId",msg.getMessageId());
jsonObject.put("taskId",msg.getTaskId());
jsonObject.put("title",msg.getTitle());
jsonObject.put("content",msg.getContent());
GTPushHelper.onNotificationMessageArrived(jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}

//点击回调
@Override
public void onNotificationMessageClicked(Context context, GTNotificationMessage msg) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("messageId",msg.getMessageId());
jsonObject.put("taskId",msg.getTaskId());
jsonObject.put("title",msg.getTitle());
jsonObject.put("content",msg.getContent());
GTPushHelper.onNotificationMessageClicked(jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
}

0 comments on commit 086ac81

Please sign in to comment.