I am trying to define constant in .C file and use that constant in .Class file in my class. How can I do that? I am totally new for NDK. I defined constant here.
const jstring BASE_URL ="http://www.google.com";'
currently i am using that constant by calling an method
jstring
Java_com_example_hellojni_HelloJni_variableData(JNIEnv *env) {
return (*env)->NewStringUTF(env, BASE_URL);
}
How can i Use it directly in my java code
Your method works. I can give you another way from my experience:
Create a custom java object with a String field and a method that returns a String.
Class Container{
private String baseUrl;
public String getBaseUrl(){
return baseUrl;
}
}
Create a Java native method and pass Container as an argument
On the side of C/C++, you can modify Container's fields here are jni funtions' reference that could help you http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html