Problems with starting an Android activity from Qt



  • Hello,

    I have a small camera project with an activity that starts the "oem-camera-app" and receives a file-uri. I am trying to start the activity in a C++-function called startCamera() in mainwindow.cpp.

    But i get exceptions and errors like:

    F art     : art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.vmi.cameratester.StartCameraActivity }
    F art     : art/runtime/java_vm_ext.cc:470]   at void android.app.Instrumentation.checkStartActivityResult(int, java.lang.Object) (Instrumentation.java:1816)
    

    The problem is that i don not know how to start the android-activity in a good way. When i print the activity that Qt lives in it says: org.qtproject.qt5.android.bindings.QtActivity. But i dont know if that is OK. I tried to change org.qtproject.qt5.android.bindings in AndroidManifest.xml to for example com.vmi.cameratester but then i got "broken pipe" errors if i remember right.

        QAndroidJniObject mainActivity = QtAndroid::androidActivity();
    
        //When to use this pm?
        QAndroidJniObject pm = mainActivity.callObjectMethod("getPackageManager",
                                                                     "()Landroid/content/pm/PackageManager;");
        if (mainActivity.isValid())
        {
            QAndroidJniObject gotClass = mainActivity.callObjectMethod("getClass", "()Ljava/lang/Class;");
            QAndroidJniObject gotClassName = gotClass.callObjectMethod("getName", "()Ljava/lang/String;");
            qDebug()<<"This is mainActivity classname: " << gotClassName.toString();
    
            //How to write these param:s correct?
            QAndroidJniObject param1 = QAndroidJniObject::fromString("com.vmi.cameratester");
            QAndroidJniObject param2 = QAndroidJniObject::fromString("com.vmi.cameratester.StartCameraActivity");
    
            QAndroidJniObject intent2("android/content/Intent", "(Ljava/lang/String;)V", param2.object<jstring>());
    
            if (intent2.isValid())
            {
                    qDebug()<<"intent2 is valid";
                    mainActivity.callMethod<void>("startActivity","(Landroid/content/Intent;)V",intent2.object<jobject>());  //The problem might be here
            }
            else
            {
                qDebug()<<"intent2 is not valid";
            }
    }
    

    Someone who know how to start the activity StartCameraActivity in a good way? And i also want to receive the file-uri to Qt, but thats a latter problem i think.


  • Moderators

    @pga4711 I'm not an Android expert, but doesn't your app need the access right to use the camera? Did you set this in the manifest file?



  • @jsulm
    Yes that's right, it is necessary. Thank you. I thought i added persmissions for a week ago, but i might have deleted it when i was fiddling with the AndroidManifest.xml and build.gradle and support-librariy-issues.

    But the issues with starting activities and doing intents right persist. :/
    Hmm, for example, as i understood it, you could prepare your intents in a lot of ways. Like directly in the Intent-constructor, or with setClassName(...). And when my activities are in totally different packages things will be more complex. I think my app starts with org.qtproject.qt5.android.bindings.QtActivity and then i would like to do an intent to com.vmi.cameratester.StartCameraActivity.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.