0

I successfully managed wifi enable through java code with Android studio but not able to do same with qt c/c++.. i have tried the java method.. it's working perfectly in android

public static  void enableWifi(Context context){
    WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(true);//Turn on Wifi
    }

calling from c/c++ :

QAndroidJniObject::callStaticMethod<void>("com/app/MyJavaClass",
                                                           "enableWifi",
                                                         "(Landroid/content/Context;)V",
                                                            QtAndroid::androidContext().object());

I wasn't able to enable wifi in Android device using c/c++.. how can i achieve this? please help me out... Thanks in advance

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
sirisha
  • 9
  • 2
  • I tested with Android, and it does work, I could do both enable and disable `WiFi`, How and where you configured your java class in Qt? – Mohammad Kanan May 10 '18 at 19:24
  • I was tried to connect wifi when click on button in Qt.. This is the way i am calling method from c++ void calljava::wificonnection(){ QAndroidJniObject::callStaticMethod("com/app/sampleandroidproject/MyJavaClass", "enableWifi", "(Landroid/content/Context;)V", QtAndroid::androidContext().object()); } – sirisha May 11 '18 at 05:13
  • is any permissions required like android for wifi in qt? please help me – sirisha May 11 '18 at 05:17
  • Have look at this [post](https://stackoverflow.com/questions/48940444/where-does-qt-look-for-java-classes-when-using-jni/48950527#48950527) and make sure you doing it correctly. add permissions _ACESS_WIFI_STATE_, _CHANGE_WIFI_STATE_ – Mohammad Kanan May 11 '18 at 10:35
  • I did the same way... I have added permissions in manifest file. But I wasn't able to enable wifi. – sirisha May 11 '18 at 11:12
  • I just added manifest file under android source directory in Qt.. is manifest need to call anywhere ? – sirisha May 11 '18 at 11:14
  • What do you mena by _call anywhere_ ? – Mohammad Kanan May 11 '18 at 11:15
  • I have added like this in my .pro file DISTFILES += \ android/src/MyJavaClass.java \ android/src/AndroidManifest.xml When i click on button, calling wifi related method.. i am getting log like this I/WifiManager( 4935): setWifiEnabled : true But not able to connect wifi.. please help me – sirisha May 11 '18 at 11:19

0 Answers0