zono
zono

Reputation: 8584

JNI: How to substring? How to get caller's package name? Call C code from Java on Android

I could call a very simple JNI method below from Java on Android somehow. However I have no idea what should I do next.

JNIEXPORT jstring JNICALL Java_com_test_ndktest_MyActivity_HelloJNI
  (JNIEnv *env, jobject obj)
  {
    (*env)->NewStringUTF(env, "Hello from JNI");
  } 

What I want to do are two things...

  1. What is compatible Java's substring method.
String str1 = new String("Hello World!");
String new_str1 = str1.substring(2, 5);
System.out.println(new_str1); // llo
  1. I want to have a limitation to call

I may be able to get caller's package name. I want to avoid calling by unexpecting callers.

I am very grateful if you can share any hints or advices.

Thanks

Upvotes: 0

Views: 830

Answers (1)

QArea
QArea

Reputation: 4981

Why don't you do that in Java? As for me the better way is to do this things in java. Sorry if i din't understand something.

As you know you can use C/C++. Did you see this: Elegant way to copy substring from char* to std::string or http://www.cplusplus.com/reference/string/string/string/?

Upvotes: 2

Related Questions