0

j'ai pu trouver un code qui crée un service pour Android en utilisant Qt dans ce lien: https://github.com/bbernhard/qtandroidservices_exampleQT Android: ne peut pas créer un service android dans .donc séparé

Cependant, quand j'ai essayé de mettre le service code dans un autre fichier .so en utilisant ce lien: https://www.kdab.com/qt-android-create-android-service-using-qt/

Je ne vois plus le service en arrière-plan de mon appareil Android! Et je ne peux pas trouver de réponses à ce problème n'importe où. Si quelqu'un peut trouver le problème dans mon code ou partager un exemple de code qui serait génial!

Voici mon code:

Manifest: (entrées correspondant)

<manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto"> 
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --"> 
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.example.MyCustomAppActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop"> 
<intent-filter> 
<action android:name="android.intent.action.MAIN"/> 
<category android:name="android.intent.category.LAUNCHER"/> 
</intent-filter> 
<meta-data android:name="android.app.lib_name" android:value="qtandroidservices_example"/> 
</activity> 

<service android:process=":qt" android:enabled="true" android:name="org.qtproject.example.MyCustomAppService"> 
<meta-data android:name="android.app.lib_name" android:value="server"/> 

     <!-- Background running --> 
     <meta-data android:name="android.app.background_running" android:value="true"/> 
     <!-- Background running --> 
    </service> 
</application> 
</manifest> 

======================== =====================================

MyCustomAppActivity.java:

package org.qtproject.example; 
import org.qtproject.example.R; 
import org.qtproject.qt5.android.bindings.QtActivity; 
import org.qtproject.qt5.android.bindings.QtService; 
import org.qtproject.example.MyCustomAppService; 
import android.content.Intent; 
import android.util.Log; 
import android.os.Bundle; 

public class MyCustomAppActivity extends QtActivity { 
@Override 
public void onCreate(Bundle bundle) { 
super.onCreate(bundle); 
Log.i("Activity", "Starting service!"); 
Intent serviceIntent = new Intent(this, org.qtproject.example.MyCustomAppService.class); 
startService(serviceIntent); 
} 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
super.onActivityResult(requestCode, resultCode, data); 
} 
} 

================================================ ======= MyCustomService.java:

package org.qtproject.example; 
import android.app.Service; 
import android.os.IBinder; 
import android.content.Intent; 
import android.os.Bundle; 
import org.qtproject.qt5.android.bindings.QtService; 
import android.util.Log; 

public class MyCustomAppService extends QtService { 

/** Called when the service is being created. */ 
@Override 
public void onCreate() { 
Log.i("Service", "Service created!"); 
super.onCreate(); 

} 

/** The service is starting, due to a call to startService() */ 
@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
Log.i("Service", "Service created!"); 
int ret = super.onStartCommand(intent, flags, startId); 
return ret; 
//return mStartMode; 
} 
} 

====================================== =============

server.pro:

TEMPLATE = lib 
TARGET = server 
CONFIG += dll 
QT += core 
SOURCES += 
server.cpp 

====================== ===================

server.cpp:

#include <QDebug> 
#ifdef Q_OS_ANDROID 
#include <QAndroidJniObject> 
#include <QtAndroid> 
#endif 

int main(int argc, char *argv[]) 
{ 
QGuiApplication app(argc, argv); 

qWarning("I am serving"); 
return app.exec(); 
} 

Répondre

0

J'ai eu le même problème. J'ai dû ajouter la bibliothèque de serveurs résultante à l'APK Android. Je l'ai ajouté dans les paramètres du projet dans QtCreator sous Build/Build Android APK/Bibliothèques supplémentaires et sélectionné le fichier create so.