如何在QAndroidjniobject中传递参数?

时间:2018-11-26 08:48:18

标签: android qt qml qtquick2 android-wifi

我正在尝试将Android代码添加到qt项目中。 这是我的.java代码

public class WifiReceiver extends BroadcastReceiver
{

static  String ssid;

@Override
  public void onReceive(Context context, Intent intent) {

     NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
     if(info != null && info.isConnected()) {
       // Do your work.

       // e.g. To check the Network Name or other info:
       WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
       WifiInfo wifiInfo = wifiManager.getConnectionInfo();
       ssid = wifiInfo.getSSID();
       getinfo();
     }
  }
 public static String getinfo()
 {
     return ssid;
 }
}

我的cpp代码是

void WIFICLASS::updateAndroidNotification()
{

qDebug()<<"******************************************8";
    QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/WifiReceiver","onReceive","(Landroid/content/Context;Landroid/content/Intent;)V;",QtAndroid::androidContext().object());

    QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/WifiReceiver","getinfo","()Ljava/lang/String;");


      QString user = returnString.toString();


     qDebug()<<"answer"<<user;

    }

应该为(Landroid/content/Context;Landroid/content/Intent;)V;",QtAndroid::androidContext().object());使用什么参数,就像在Java代码中一样?我正在使用void onReceive(Context context,Intent intent) intent 作为参数。.

0 个答案:

没有答案