Android JNI_OnLoad
2015-07-13 17:29
555 查看
http://zhidao.baidu.com/link?url=VZS2_Nx-prapV2fQ_uUyqTghX4hNu-GKR8MdaKlwiGOHz3DR52EsVlDeyuIkBduu_IPD8WnGDFzf3nR2cYClsyZfUXrcgdYkoOiGKZ5dvg3
http://blog.chinaunix.net/uid-26993600-id-3303022.html http://blog.sina.com.cn/s/blog_7a2ffd5c01013vrv.html http://blog.csdn.net/imyfriend/article/details/9117917
#include <string.h>
#include <jni.h>
#include <assert.h>
char * s1 = "hello s1";
extern "C" {
jstring Java_com_example_helloworld_MainActivity_stringFromJNI( JNIEnv* env, jobject thiz )
{
return env->NewStringUTF(s1);
}
}
JNIEXPORT jstring JNICALL native_hello(JNIEnv *env, jclass clazz)
{
return env->NewStringUTF("hello world returned.");
}
#define JNIREG_CLASS "com/example/helloworld/MainActivity"
static JNINativeMethod gMethods[] = {
{ "hello", "()Ljava/lang/String;", (void*)native_hello },
};
static int registerNativeMethods(JNIEnv* env, const char* className,
JNINativeMethod* gMethods, int numMethods)
{
jclass clazz;
clazz = env->FindClass(className);
if (clazz == NULL) {
return JNI_FALSE;
}
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
return JNI_FALSE;
}
return JNI_TRUE;
}
static int registerNatives(JNIEnv* env)
{
if (!registerNativeMethods(env, JNIREG_CLASS, gMethods,
sizeof(gMethods) / sizeof(gMethods[0])))
return JNI_FALSE;
return JNI_TRUE;
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL;
jint result = -1;
if (vm->GetEnv( (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
return -1;
}
assert(env != NULL);
if (!registerNatives(env)) {
return -1;
}
result = JNI_VERSION_1_4;
s1 = "hellow s2";
//return -1;
return result;
}
http://blog.chinaunix.net/uid-26993600-id-3303022.html http://blog.sina.com.cn/s/blog_7a2ffd5c01013vrv.html http://blog.csdn.net/imyfriend/article/details/9117917
#include <string.h>
#include <jni.h>
#include <assert.h>
char * s1 = "hello s1";
extern "C" {
jstring Java_com_example_helloworld_MainActivity_stringFromJNI( JNIEnv* env, jobject thiz )
{
return env->NewStringUTF(s1);
}
}
JNIEXPORT jstring JNICALL native_hello(JNIEnv *env, jclass clazz)
{
return env->NewStringUTF("hello world returned.");
}
#define JNIREG_CLASS "com/example/helloworld/MainActivity"
static JNINativeMethod gMethods[] = {
{ "hello", "()Ljava/lang/String;", (void*)native_hello },
};
static int registerNativeMethods(JNIEnv* env, const char* className,
JNINativeMethod* gMethods, int numMethods)
{
jclass clazz;
clazz = env->FindClass(className);
if (clazz == NULL) {
return JNI_FALSE;
}
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
return JNI_FALSE;
}
return JNI_TRUE;
}
static int registerNatives(JNIEnv* env)
{
if (!registerNativeMethods(env, JNIREG_CLASS, gMethods,
sizeof(gMethods) / sizeof(gMethods[0])))
return JNI_FALSE;
return JNI_TRUE;
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL;
jint result = -1;
if (vm->GetEnv( (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
return -1;
}
assert(env != NULL);
if (!registerNatives(env)) {
return -1;
}
result = JNI_VERSION_1_4;
s1 = "hellow s2";
//return -1;
return result;
}
package com.example.helloworld; import android.widget.TextView; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity { private TextView textview1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview1 = (TextView)findViewById(R.id.textview1); textview1.setText(stringFromJNI()); textview1.setText(hello()); } public native String stringFromJNI(); public static native String hello(); static { System.loadLibrary("helloworld"); } }
相关文章推荐
- android studio图片未能识别
- Android Layout属性笔记
- android 软件 安装 卸载 启动 分享 桌面快捷方式
- Android 数据库SQLite Cursor数据遍历读取
- android悬浮窗应用
- 使用WIFI连接android进行调试和adb操作
- android各种资源的详细解释
- 手电筒的制作
- Androidの自定义对话框AlertDialog(一)
- android线程销毁
- android知识杂记(二)
- Android Fragment 真正的完全解析
- Android Fragment 真正的完全解析
- 基于Jenkins+git+gradle的android持续集成
- Tablayout(Android) 的几个重要属性
- android studio中出现的问题
- Android EditText输入最大值提示功能
- android知识杂记(一)
- 【Android】设置全屏和横屏
- android studio配置AndroidAnnotations