android - Return and access java object/class from jni -
i have java method returns instance of object/class 'readcommpacket'. call java method initiated ndk/jni side(c++ -> java-> return-> java object-> c++). how complete this, i'm struggling proper jni calls/signatures complete this. appreciated.
java object/class used return.
public class readcommpacket { public byte[] rcpbtyeread; public int rcpbytecount; public readcommpacket(byte[] btyeread, int bytecount){ this.rcpbtyeread = btyeread; this.rcpbytecount = bytecount; } }
java method called jni
public readcommpacket btmsgtondkcomm(){ if(bluetoothconnectedrunnable != null){ return bluetoothconnectedrunnable.readbt();//returns readcommpacket obj } return new readcommpacket(null, -1); }
jni/ndk c/c++ code
void recvfrombluetooth(char * recvdbyte){ jnimethodinfo methodinfo; if (! getmethodinfo(&methodinfo, "btmsgtondkcomm", "v"))//what signature use? { logd("cannot find method!"); return; } //retreive btye[] , int readcommpacket here. jni calls? }
signature contains package name.
let’s suppose package name com.example
then signature in example be:
()lcom/example/readcommpacket
p.s. if call method c++, make sure class name & method name not obfuscated pro guard (if use it)
Comments
Post a Comment