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. How get result from system activity? ( ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION )
Forum Updated to NodeBB v4.3 + New Features

How get result from system activity? ( ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION )

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 161 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.
  • C Offline
    C Offline
    Compozitor
    wrote on last edited by
    #1

    There is a task to copy files from application resources to the device for further work with them when the application is launched.

    When the application is launched, I launch an activity that asks to grant the application the right to access all files.
    I manually grant the application this right, but for reasons unknown to me, the application, having received permission, does not copy files to the device, but does this only when the application is launched again.

    And I wanted to track the result of the activity using the result class inherited from QAndroidActivityResultReceiver, the reference to which is specified in the call QtAndroid::startActivity(intent, 118, &result) but analyzing the execution of the program, I conclude that the void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) method was not called when working with the activity.

    And finally, a question: Why does the activity that asks to grant the application access rights to all files not give any results in the method handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)?

    It seems that this method is simply not called.

    ActivityResult result;
    
    jboolean value = QAndroidJniObject::callStaticMethod<jboolean>("android/os/Environment", "isExternalStorageManager");
        if (value == false)
        {
          // Get packege name (exemple: "package:org.appname.test")
          QAndroidJniObject activity = QtAndroid::androidActivity();
          QAndroidJniObject context = activity.callObjectMethod("getApplicationContext", "()Landroid/content/Context;");
          QAndroidJniObject packageName = context.callObjectMethod("getPackageName", "()Ljava/lang/String;");
          QString sPackageName = "package:"+packageName.toString();
    
          // Get permission to access all files
          QAndroidJniObject ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION = QAndroidJniObject::getStaticObjectField( "android/provider/Settings", "ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION","Ljava/lang/String;" );
          QAndroidJniObject intent("android/content/Intent", "(Ljava/lang/String;)V", ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION.object());
          QAndroidJniObject jniPath = QAndroidJniObject::fromString(sPackageName);
          QAndroidJniObject jniUri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", jniPath.object<jstring>());
          QAndroidJniObject jniResult = intent.callObjectMethod("setData", "(Landroid/net/Uri;)Landroid/content/Intent;", jniUri.object<jobject>() );
    
    
          QtAndroid::startActivity(intent, 118, &result);
    
        value = QAndroidJniObject::callStaticMethod<jboolean>("android/os/Environment", "isExternalStorageManager");
        if (value == true)
        {
          // Copying files
          
        }
    

    File activity_result.h

    class ActivityResult : public QObject, public QAndroidActivityResultReceiver
    {
      Q_OBJECT
    private:
      int m_receiverRequestCode = 1000;
      int m_resultCode = 2000;
      QString m_resultData = " !!! ";
    
      void setReceiverRequestCode(int in) { m_receiverRequestCode = in; }
      void setResultCode(int in) { m_resultCode = in; }
      void setResultData(QString in) { m_resultData = in; }
    
    public:
        ActivityResult() {}
        int receiverRequestCode() { return m_receiverRequestCode; }
        int resultCode() { return m_resultCode; }
        QString resultData() { return m_resultData; }
    
        void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) override
        {
       // Only for test
       // Test that a method is being called
          setResultCode(11);
        }
    };
    
    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