Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b8036c

Browse files
Create README.md
1 parent 2480dd3 commit 7b8036c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎JniSample/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Jni android sample
2+
3+
JNI stands for Java Native Interface. This sample is showing how to call native c/c++ method to be used inside android.
4+
In order to run this sample, you need to install <b>NDK</b> in android SDK manager beforehand.
5+
6+
If you looked through, the project contains c/c++ file which contains:
7+
8+
#include <jni.h>
9+
#include "sample-jni.h"
10+
11+
12+
extern "C"
13+
JNIEXPORT jint JNICALL
14+
15+
Java_com_pramonow_androidadvanced_JniActivity_getKey(JNIEnv* pEnv, jobject instance, jint key1) {
16+
return key1+200;
17+
}
18+
19+
And the getKey function will be able to be called inside the activity:
20+
21+
//Our Jni method
22+
external fun getKey(key:Int):Int
23+
24+
companion object {
25+
init {
26+
System.loadLibrary("sample-jni")
27+
}
28+
}
29+
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
32+
setContentView(R.layout.activity_jni)
33+
34+
Toast.makeText(this,getKey(55).toString(),Toast.LENGTH_SHORT).show() // will show 255
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /