Skip to content

Instantly share code, notes, and snippets.

@sdkfz181tiger
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdkfz181tiger/711ca3837ea2956ab90b to your computer and use it in GitHub Desktop.
Save sdkfz181tiger/711ca3837ea2956ab90b to your computer and use it in GitHub Desktop.
JNI
//
// UtilNativeJNI.cpp
// Oyadius1
//
// Created by Shimeji Ozaki on 2014-02-04.
//
//
#include "UtilNativeJNI.h"
#include <jni.h>
#include <android/log.h>
#include "platform/android/jni/JniHelper.h"
#define TAG "UtilNativeJNI"
#define log(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define CLASS_NAME "com/ozateck/oyadius1/MainActivity"
using namespace cocos2d;
using namespace std;
//==========
// JNIメソッドパターン
void testMethodJNI(){
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, CLASS_NAME, "testMethod", "()V")){
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
void testMethodIntJNI(int num){
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, CLASS_NAME, "testMethodInt", "(I)V")){
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, num);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
void testMethodStrJNI(const char* msg){
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, CLASS_NAME, "testMethodStr", "(Ljava/lang/String;)V")){
jstring stringArg = methodInfo.env->NewStringUTF(msg);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(stringArg);
}
}
void testMethodBoolJNI(bool b){
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, CLASS_NAME, "testMethodBoolean", "(Z)V")){
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, b);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
//
// UtilNativeJNI.h
// Oyadius1
//
// Created by Shimeji Ozaki on 2014-02-04.
//
//
#ifndef __OyajiGallaga__UtilNativeJNI__
#define __OyajiGallaga__UtilNativeJNI__
// JNIメソッドパターン
extern void testMethodJNI();
extern void testMethodIntJNI(int num);
extern void testMethodStrJNI(const char* msg);
extern void testMethodBoolJNI(bool b);
#endif /* defined(__OyajiGallaga__UtilNativeJNI__) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment