Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting broadcast messages on Android



  • I've been trying to detect when an application is installed or removed, I added this to my manifest

    @
    <receiver android:name="com.iktwo.utils.PackageChangedReceiver">
    <intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <action android:name="android.intent.action.PACKAGE_REMOVED" />
    <action android:name="android.intent.action.PACKAGE_CHANGED"/>
    <action android:name="android.intent.action.PACKAGE_REPLACED"/>
    <data android:scheme="package" />
    </intent-filter>
    </receiver>
    @

    That works fine, onReceive is executed in my class, but I've been trying to get a signal in Qt, so I was following the help

    @
    void registerNativeMethods() {
    JNINativeMethod methods[] {{"callNativeOne", "(I)V", reinterpret_cast<void *>(fromJavaOne)},
    {"callNativeTwo", "(I)V", reinterpret_cast<void *>(fromJavaTwo)}};

    QAndroidJniObject javaClass("com/iktwo/utils/QPackageManager");
    QAndroidJniEnvironment env;
    jclass objectClass = env->GetObjectClass(javaClass.object<jobject>());
    env->RegisterNatives(objectClass,
                         methods,
                         sizeof(methods) / sizeof(methods[0]));
    env->DeleteLocalRef(objectClass);
    

    }
    @

    but I get this exception

    @java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()@

    I was looking at how is it implemented for bluetooth in 5.3 but still I can't get it to work, is there something I'm missing or doing wrong? Thanks!


Log in to reply