2016-09-20 94 views
-1

,但我有一個問題:JNI:如何使用的GetMethodID因爲我要調用java用C雖然JNI getScanResults

我的代碼如下:

m = (*env)->GetMethodID(env, clazz, "getScanResults", "()[B"); 
LOG_INFO("startScan Failed %d, %d", __LINE__,m); 
jobjectArray rArray = (*env)->CallObjectMethod(env, wifiMgrObj, m); 
... 

但 'M' 總是返回0 我認爲「()[B]可能是錯誤的,但我不知道如何FIXIT,任何人都可以幫助我嗎?


以下是有關Android的API '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. 
+0

看到http://www.rgagnon.com/javadetails/java-0286.html – pskink

+0

我知道了,謝謝 – zs2014

回答

1
  • 你有引說,它返回一個List<ScanResult>的API。
  • 您提供給GetMethodID()的JNI簽名表示它返回byte[]。它沒有。

道德:不要猜測JNI簽名。使用javap -s的結果。這絕不是錯的。

+0

你能給我一個例子嗎?我嘗試過,但不工作: m =(* env) - > GetMethodID(env,clazz,「getScanResults」,「()[​​ScanResult」); – zs2014

+0

@ zs2014正如EJP所說:「道德:不要猜測關於JNI簽名的問題」,是否嘗試過'javap -s'?這將回答你的問題 – pskink

+0

@ zs2014我不知道你爲什麼需要'javap -s'的例子。我無法說服自己,你實際上已經閱讀我的答案。 – EJP