-
Notifications
You must be signed in to change notification settings - Fork 11
/
JniCallbackDemo.java
75 lines (60 loc) · 1.43 KB
/
JniCallbackDemo.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.lxk.ndkdemo;
import android.os.Build;
import android.util.Log;
import androidx.annotation.Keep;
/**
* @author https://github.com/103style
* @date 2019/8/22 10:42
* 演示在C中如何调用Java
*/
public class JniCallbackDemo {
private static final String TAG = "JniCallbackDemo";
static {
System.loadLibrary("jni_callback");
}
/**
* 时间统计
*/
private int timeCount;
/**
* 开始计时
*/
public native void startTiming();
/**
* 停止计时
*/
public native void stopTiming();
/**
* 输出开始计时后的每一秒
*/
@Keep
private void printTime() {
Log.e(TAG, "timeCount = " + timeCount);
timeCount++;
}
/**
* Keep :保证类名不被混淆
*/
@Keep
public static class JniHandler {
/**
* Keep :保证方法名不被混淆
*/
@Keep
public static String getBuildVersion() {
return Build.VERSION.RELEASE;
}
@Keep
public long getRuntimeMemorySize() {
return Runtime.getRuntime().freeMemory();
}
@Keep
private void updateStatus(String msg) {
if (msg.toLowerCase().contains("error")) {
Log.e("JniHandler", "Native Err: " + msg);
} else {
Log.i("JniHandler", "Native Msg: " + msg);
}
}
}
}