Hi,
I'd like to use QtAndroidExtras but I'm wondering if it's even possible in my case. Maybe you know the answer. My Qt version is 6.2, so current interface differ a little bit.
I have service in Android:
<intent-filter>
<action android:name="com.my.service.MY_SERVICE" />
</intent-filter>
I have a java class ServiceBinder (separate app) which implements ServiceConnection (onServiceConnected, onServiceDisconnected). That class create an Intent (above one)
Intent intent = new Intent();
intent.setAction(ServiceBinder.INTENT_ACTION);
and bind to service.
In my QT app I create QJniObject from my ServiceBinder:
QJniObject binder = QJniObject(ServiceBinderClassName,
"(Landroid/content/Context;J)V",
QNativeInterface::QAndroidApplication::context(),
reinterpret_cast<long>(this));
Then onSerivceConnected ServiceBinder uses JINI call to my qt app where ndk binder is created, connection is established and callbacks are registered.
So my Question is, can I replace those JINI calls and Java class simply by using QAndroidServiceConnection ? I've tired to do it but without success.
qDebug() << "Start";
QAndroidIntent intent("com.my.service.MY_SERVICE");
const QJniObject jini = intent.handle();
if (jini.isValid()) {
qDebug() << "VALID...";
qDebug() << "bindService started...";
ServiceConnection *serviceConnection = new ServiceConnection();
QtAndroidPrivate::bindService(intent, *serviceConnection, QtAndroidPrivate::BindFlag::AutoCreate);
}
qDebug() << "bindService ended...";
ServiceConnection class inherits from QAndroidServiceConnection and implements onServiceConnected etc.
and here is the output:
D Start
D VALID...
D bindService started...
W System.err: java.lang.ClassNotFoundException: Didn't find class "org.qtproject.qt.android.extras.QtAndroidServiceConnection" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /system/system_ext/lib64, /system/product/lib64]]
W System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
W System.err: at org.qtproject.qt.android.QtNative.startQtApplication(Native Method)
W System.err: at org.qtproject.qt.android.QtNative$7.run(QtNative.java:650)
W System.err: at org.qtproject.qt.android.QtThread$1.run(QtThread.java:61)
W System.err: at java.lang.Thread.run(Thread.java:923)
W System.err: java.lang.IllegalArgumentException: connection is null
W System.err: at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1810)
W System.err: at android.app.ContextImpl.bindService(ContextImpl.java:1749)
W System.err: at android.content.ContextWrapper.bindService(ContextWrapper.java:756)
W System.err: at org.qtproject.qt.android.QtNative.startQtApplication(Native Method)
W System.err: at org.qtproject.qt.android.QtNative$7.run(QtNative.java:650)
W System.err: at org.qtproject.qt.android.QtThread$1.run(QtThread.java:61)
W System.err: at java.lang.Thread.run(Thread.java:923)