Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problems with starting an Android activity from Qt
Forum Updated to NodeBB v4.3 + New Features

Problems with starting an Android activity from Qt

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pga4711
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • P pga4711

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      2
      • jsulmJ jsulm

        @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?

        P Offline
        P Offline
        pga4711
        wrote on last edited by pga4711
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved