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()


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.

Need Your Help

Pointer arithmatic failed to compile, gcc says invalid type conversion

c++ pointers gcc compilation difference

I wish to calculate the distance between a program's bss section and the start of heap section, so I've got a program like this:

Trouble Linking External JavaScript with Jekyll

javascript jquery github jekyll

I have a site hosted by GitHub that uses Jekyll, and I've been (successfully) using an internally defined script in each layout that will generate a random tagline from an array of them.