Using getRssi from QAndroidJniObject (Qt Widget)
-
Hi guys,
I'm currently developing an application (widget, not qml) to connect an android device to a server using wifi connection; i've already established the connection between those but i'm still figuring out how to know the strength of the connection.
As the "official Android page says":http://developer.android.com/reference/android/net/wifi/WifiInfo.html the function i want to use is in the class WifiInfo and it's called getRssi, so i'm following "this official guide":https://www.qtdeveloperdays.com/sites/default/files/BogdanVatra_Extending_Qt_Android_Apps_with_JNI.pdf to access it from qt using QAndroidJniObject.
I've already added QT += androidextras in my pro file and #include <QAndroidJniObject> in my cpp file, i've added this permissions in the manifest file:
@<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>@
and then i've added this code:
@int value = QAndroidJniObject::callStaticMethod<jint>("android/net/wifi/WifiInfo", "getRssi", "(I)I");
qDebug() << value;@
but the output is always 0 (it refresh every 50 milliseconds).
What am I doing wrong?
Thanks a lot for the answers!EDIT: I've found that the problem was that the access to the folder android/net/wifi, so i've made a java file with android native code with the code of getting rssi, and i've linked to qt in the file pro, i've changed the android manifest inserting this file and i've made the access of the function in this file with the same method, and now it works. Problem solved.