JNI: how to use GetMethodID for getScanResults
I want to call java in C though jni, but I have a problem:
My code as follows:
m = (*env)->GetMethodID(env, clazz, "getScanResults", "()[B"); LOG_INFO("startScan Failed %d, %d", __LINE__,m); jobjectArray rArray = (*env)->CallObjectMethod(env, wifiMgrObj, m); ...
but 'm' always return 0. I think "()[B" maybe wrong, but i don't know howto FIXIT, can anyone help me?
Here is the android API about 'getScanResults' https://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()
getScanResults Added in API level 1 List<ScanResult> getScanResults () Return the results of the latest access point scan. Returns List<ScanResult> the list of access points found in the most recent scan. An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get valid results. If there is a remote exception (e.g., either a communication problem with the system service or an exception within the framework) an empty list will be returned.
- The API you have cited says it returns a List<ScanResult>.
- The JNI signature you have provided to GetMethodID() says it returns a byte. It doesn't.
Moral: don't guess about JNI signatures. Use the result of javap -s. It is never wrong.