1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
//
// Created by asura on 2020/4/24.
//
#include "com_example_jnidemo2_MainActivity.h"
/*
* Class: com_example_jnidemo2_MainActivity
* Method: get_reflection_field
* Signature: ()Ljava/lang/String;
*/
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_jnidemo2_MainActivity_get_1reflection_1field(JNIEnv *env, jobject obj) {
auto clazz = env->FindClass("com/example/jnidemo2/MainActivity");
auto fieldId = env->GetFieldID(clazz, "ReflectionField", "Ljava/lang/String;");
auto pJstring = (jstring) env->GetObjectField(obj, fieldId);
return pJstring;
}
/*
* Class: com_example_jnidemo2_MainActivity
* Method: get_static_reflection_field
* Signature: ()Ljava/lang/String;
*/
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_jnidemo2_MainActivity_get_1static_1reflection_1field(JNIEnv *env, jobject obj) {
auto clazz = env->FindClass("com/example/jnidemo2/MainActivity");
auto fieldId = env->GetStaticFieldID(clazz, "StaticReflectionField", "Ljava/lang/String;");
auto pJstring = (jstring) env->GetStaticObjectField(clazz, fieldId);
return pJstring;
}
/*
* Class: com_example_jnidemo2_MainActivity
* Method: set_reflection_field
* Signature: (Ljava/lang/String;)V
*/
extern "C" JNIEXPORT void JNICALL
Java_com_example_jnidemo2_MainActivity_set_1reflection_1field(JNIEnv *env, jobject obj,jstring str)
{
auto clazz = env->FindClass("com/example/jnidemo2/MainActivity");
auto fieldId = env->GetFieldID(clazz, "ReflectionField", "Ljava/lang/String;");
env->SetObjectField(obj,fieldId,str);
}
/*
* Class: com_example_jnidemo2_MainActivity
* Method: set_static_reflection_field
* Signature: (Ljava/lang/String;)V
*/
extern "C" JNIEXPORT void JNICALL
Java_com_example_jnidemo2_MainActivity_set_1static_1reflection_1field(JNIEnv *env, jobject obj, jstring str)
{
auto clazz = env->FindClass("com/example/jnidemo2/MainActivity");
auto fieldId = env->GetStaticFieldID(clazz, "StaticReflectionField", "Ljava/lang/String;");
env->SetStaticObjectField(clazz,fieldId,str);
}
|