HelloWorldImpl.c
==============
#include <jni.h>
#include "demo_HelloWorld.h"
#include <stdio.h>
#include <string.h>
int j = 0;
JNIEXPORT void JNICALL
Java_demo_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj, jstring i)
{
char s[]={'a', 'b', 'c'};
char *c = (*env)->GetStringUTFChars(env, i, 0);
char cc [128];
strcpy(cc, c);
(*env)->ReleaseStringUTFChars(env, i, c);
printf("from java;;;%s", cc);
/**
printf(i);
char *str = (*env)->GetStringUTFChars(env, string, 0);
char cap[128];
strcpy(cap, str);
(*env)->ReleaseStringUTFChars(env, string, str);
printf(str);
*/
return;
}
JNIEXPORT jstring JNICALL Java_demo_HelloWorld_c2java
(JNIEnv * env, jobject obj, jbyteArray mobileno, jbyteArray smscontent, jstring str0)
{
jstring jstr;
char str[]={'a', 'b', 'c'};
char cap[128];
const char *str1 = (*env)->GetStringUTFChars(env, str0, 0);
char * pSmscontent ;
//jsize theArrayLengthJ = (*env)->GetArrayLength(env,mobileno);
jbyte * arrayBody = (*env)->GetByteArrayElements(env,mobileno,0);
char * pMobileNo = (char *)arrayBody;
printf("[%s]\n ", pMobileNo);
//jsize size = (*env)->GetArrayLength(env,smscontent);
arrayBody = (*env)->GetByteArrayElements(env,smscontent,0);
pSmscontent = (char *)arrayBody;
printf("<%s>\n", pSmscontent);
// return SmsSend(pMobileNo,pSmscontent);
jstr=(*env)->NewStringUTF(env, str);
strcpy(cap, str1);
printf("from java ==%s", cap);
return jstr;
}
JNIEXPORT jint JNICALL Java_demo_HelloWorld_get
(JNIEnv * env, jobject obj)
{
return j;
}
/*
* Class: demo_HelloWorld
* Method: set
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_demo_HelloWorld_set
(JNIEnv * env, jobject obj, jint i)
{
j = i;
}
JNIEXPORT jint JNICALL Java_demo_HelloWorld_getIntLength
(JNIEnv * env, jobject obj, jintArray iarr)
{
jsize len = (*env)->GetArrayLength(env, iarr);
int i;
int *ielement = (*env)->GetIntArrayElements(env, iarr, 0);
printf("Int array length is %d", len);
for (i=0; i<len; i++)
printf("\nAt pos %d is %d.", i, ielement[i]);
(*env)->ReleaseIntArrayElements(env, iarr, ielement, 0);
return len*2;
}
JNIEXPORT void JNICALL Java_demo_HelloWorld_getException
(JNIEnv * env, jobject obj)
{
/* Create the Throwable object. */
jclass cls = (*env)->FindClass(env, "java/io/IOException");
jmethodID mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
jthrowable e = (*env)->NewObject(env, cls, mid);
/* Now throw the exception */
(*env)->Throw(env, e);
return;
}