How get result from system activity? ( ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION )
-
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 fromQAndroidActivityResultReceiver
, the reference to which is specified in the callQtAndroid::startActivity(intent, 118, &result)
but analyzing the execution of the program, I conclude that thevoid 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); } };