How to integrate android native code with Qt Quick project?












0














I am trying to get wifi name connected to my mobile using QAndroidJniObject.




java file:




package org.qtproject.example;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class QtAndroidToastJava extends QtActivity
{



public static String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
}


My cpp code is



void WIFICLASS::updateAndroidNotification()
{

qDebug()<<"******************************************8";

auto returnString = QAndroidJniObject::callStaticMethod <jstring>("org/qtproject/example/QtAndroidToastJava",
"getWifiName","(V;)Ljava/lang/String");

// // QString user = juser.toString();
// qDebug()<<"ANSWER"<<user;

qDebug()<<returnString;

}


After trying to build this I am getting this errors:
23: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*, char const*, ...)'



How can I solve this issue?



What is the correct way to do this?










share|improve this question
























  • Did you add QT += androidextras to the .pro file?
    – Frank Osterfeld
    Nov 23 '18 at 7:30










  • @FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
    – Ash
    Nov 23 '18 at 8:40












  • By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
    – Ash
    Nov 23 '18 at 8:55
















0














I am trying to get wifi name connected to my mobile using QAndroidJniObject.




java file:




package org.qtproject.example;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class QtAndroidToastJava extends QtActivity
{



public static String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
}


My cpp code is



void WIFICLASS::updateAndroidNotification()
{

qDebug()<<"******************************************8";

auto returnString = QAndroidJniObject::callStaticMethod <jstring>("org/qtproject/example/QtAndroidToastJava",
"getWifiName","(V;)Ljava/lang/String");

// // QString user = juser.toString();
// qDebug()<<"ANSWER"<<user;

qDebug()<<returnString;

}


After trying to build this I am getting this errors:
23: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*, char const*, ...)'



How can I solve this issue?



What is the correct way to do this?










share|improve this question
























  • Did you add QT += androidextras to the .pro file?
    – Frank Osterfeld
    Nov 23 '18 at 7:30










  • @FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
    – Ash
    Nov 23 '18 at 8:40












  • By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
    – Ash
    Nov 23 '18 at 8:55














0












0








0







I am trying to get wifi name connected to my mobile using QAndroidJniObject.




java file:




package org.qtproject.example;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class QtAndroidToastJava extends QtActivity
{



public static String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
}


My cpp code is



void WIFICLASS::updateAndroidNotification()
{

qDebug()<<"******************************************8";

auto returnString = QAndroidJniObject::callStaticMethod <jstring>("org/qtproject/example/QtAndroidToastJava",
"getWifiName","(V;)Ljava/lang/String");

// // QString user = juser.toString();
// qDebug()<<"ANSWER"<<user;

qDebug()<<returnString;

}


After trying to build this I am getting this errors:
23: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*, char const*, ...)'



How can I solve this issue?



What is the correct way to do this?










share|improve this question















I am trying to get wifi name connected to my mobile using QAndroidJniObject.




java file:




package org.qtproject.example;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class QtAndroidToastJava extends QtActivity
{



public static String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
}


My cpp code is



void WIFICLASS::updateAndroidNotification()
{

qDebug()<<"******************************************8";

auto returnString = QAndroidJniObject::callStaticMethod <jstring>("org/qtproject/example/QtAndroidToastJava",
"getWifiName","(V;)Ljava/lang/String");

// // QString user = juser.toString();
// qDebug()<<"ANSWER"<<user;

qDebug()<<returnString;

}


After trying to build this I am getting this errors:
23: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*, char const*, ...)'



How can I solve this issue?



What is the correct way to do this?







android qt wifi qtandroidextras qandroidjniobject






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 6:56









Aniruddh Parihar

2,15911027




2,15911027










asked Nov 23 '18 at 6:44









AshAsh

115




115












  • Did you add QT += androidextras to the .pro file?
    – Frank Osterfeld
    Nov 23 '18 at 7:30










  • @FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
    – Ash
    Nov 23 '18 at 8:40












  • By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
    – Ash
    Nov 23 '18 at 8:55


















  • Did you add QT += androidextras to the .pro file?
    – Frank Osterfeld
    Nov 23 '18 at 7:30










  • @FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
    – Ash
    Nov 23 '18 at 8:40












  • By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
    – Ash
    Nov 23 '18 at 8:55
















Did you add QT += androidextras to the .pro file?
– Frank Osterfeld
Nov 23 '18 at 7:30




Did you add QT += androidextras to the .pro file?
– Frank Osterfeld
Nov 23 '18 at 7:30












@FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
– Ash
Nov 23 '18 at 8:40






@FrankOsterfeld I have added QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in my pro file
– Ash
Nov 23 '18 at 8:40














By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
– Ash
Nov 23 '18 at 8:55




By adding this line QAndroidJniObject returnString = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava","getWifiName","(Landroid/content/Context)",QtAndroid::androidContext().object());** I am getting error: "W System.err: java.lang.NoSuchMethodError: no static method "Lorg/qtproject/example/QtAndroidToastJava;.getWifiName(Landroid/content/Context)"" I think I need proper arguments for context as I am using context getWifiName(Context context) as parameter to my function in java@FrankOsterfeld what should I add in place of(Landroid/content/Context).
– Ash
Nov 23 '18 at 8:55












1 Answer
1






active

oldest

votes


















0














There are two things wrong here:



1.) The message signature you are passing in C++ is wrong. It should be:



"(Landroid/content/Context;)Ljava/lang/String;"


Mind the ; at the end of each class name! It is always L<classname>;! Also, you have to always exactly match the method as declared in java. Multiple parameters do not need to be seperated. If you have e.g. a method void test(int a, int b), the signature would be (II)V.



2.) The method you are calling is an object method, which means you must use QAndroidJniObject::callStaticObjectMethod



auto res = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava",
"getWifiName",
"(Landroid/content/Context;)Ljava/lang/String;",
QtAndroid::androidContext().object());


That method returns you an QAndroidJniObject and you can call QAndroidJniObject::toString() to convert the result to a string.






share|improve this answer





















  • Thanks a lot sir! Problem got solved.
    – Ash
    Nov 23 '18 at 11:37












  • In that case you should accept/upvote the answer, so other people can see that this solved the problem.
    – Felix
    Nov 23 '18 at 12:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441800%2fhow-to-integrate-android-native-code-with-qt-quick-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There are two things wrong here:



1.) The message signature you are passing in C++ is wrong. It should be:



"(Landroid/content/Context;)Ljava/lang/String;"


Mind the ; at the end of each class name! It is always L<classname>;! Also, you have to always exactly match the method as declared in java. Multiple parameters do not need to be seperated. If you have e.g. a method void test(int a, int b), the signature would be (II)V.



2.) The method you are calling is an object method, which means you must use QAndroidJniObject::callStaticObjectMethod



auto res = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava",
"getWifiName",
"(Landroid/content/Context;)Ljava/lang/String;",
QtAndroid::androidContext().object());


That method returns you an QAndroidJniObject and you can call QAndroidJniObject::toString() to convert the result to a string.






share|improve this answer





















  • Thanks a lot sir! Problem got solved.
    – Ash
    Nov 23 '18 at 11:37












  • In that case you should accept/upvote the answer, so other people can see that this solved the problem.
    – Felix
    Nov 23 '18 at 12:34
















0














There are two things wrong here:



1.) The message signature you are passing in C++ is wrong. It should be:



"(Landroid/content/Context;)Ljava/lang/String;"


Mind the ; at the end of each class name! It is always L<classname>;! Also, you have to always exactly match the method as declared in java. Multiple parameters do not need to be seperated. If you have e.g. a method void test(int a, int b), the signature would be (II)V.



2.) The method you are calling is an object method, which means you must use QAndroidJniObject::callStaticObjectMethod



auto res = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava",
"getWifiName",
"(Landroid/content/Context;)Ljava/lang/String;",
QtAndroid::androidContext().object());


That method returns you an QAndroidJniObject and you can call QAndroidJniObject::toString() to convert the result to a string.






share|improve this answer





















  • Thanks a lot sir! Problem got solved.
    – Ash
    Nov 23 '18 at 11:37












  • In that case you should accept/upvote the answer, so other people can see that this solved the problem.
    – Felix
    Nov 23 '18 at 12:34














0












0








0






There are two things wrong here:



1.) The message signature you are passing in C++ is wrong. It should be:



"(Landroid/content/Context;)Ljava/lang/String;"


Mind the ; at the end of each class name! It is always L<classname>;! Also, you have to always exactly match the method as declared in java. Multiple parameters do not need to be seperated. If you have e.g. a method void test(int a, int b), the signature would be (II)V.



2.) The method you are calling is an object method, which means you must use QAndroidJniObject::callStaticObjectMethod



auto res = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava",
"getWifiName",
"(Landroid/content/Context;)Ljava/lang/String;",
QtAndroid::androidContext().object());


That method returns you an QAndroidJniObject and you can call QAndroidJniObject::toString() to convert the result to a string.






share|improve this answer












There are two things wrong here:



1.) The message signature you are passing in C++ is wrong. It should be:



"(Landroid/content/Context;)Ljava/lang/String;"


Mind the ; at the end of each class name! It is always L<classname>;! Also, you have to always exactly match the method as declared in java. Multiple parameters do not need to be seperated. If you have e.g. a method void test(int a, int b), the signature would be (II)V.



2.) The method you are calling is an object method, which means you must use QAndroidJniObject::callStaticObjectMethod



auto res = QAndroidJniObject::callStaticObjectMethod("org/qtproject/example/QtAndroidToastJava",
"getWifiName",
"(Landroid/content/Context;)Ljava/lang/String;",
QtAndroid::androidContext().object());


That method returns you an QAndroidJniObject and you can call QAndroidJniObject::toString() to convert the result to a string.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 10:24









FelixFelix

4,52711636




4,52711636












  • Thanks a lot sir! Problem got solved.
    – Ash
    Nov 23 '18 at 11:37












  • In that case you should accept/upvote the answer, so other people can see that this solved the problem.
    – Felix
    Nov 23 '18 at 12:34


















  • Thanks a lot sir! Problem got solved.
    – Ash
    Nov 23 '18 at 11:37












  • In that case you should accept/upvote the answer, so other people can see that this solved the problem.
    – Felix
    Nov 23 '18 at 12:34
















Thanks a lot sir! Problem got solved.
– Ash
Nov 23 '18 at 11:37






Thanks a lot sir! Problem got solved.
– Ash
Nov 23 '18 at 11:37














In that case you should accept/upvote the answer, so other people can see that this solved the problem.
– Felix
Nov 23 '18 at 12:34




In that case you should accept/upvote the answer, so other people can see that this solved the problem.
– Felix
Nov 23 '18 at 12:34


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441800%2fhow-to-integrate-android-native-code-with-qt-quick-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...