Holiday gift 2022 pieces codes to facing new Android API SDK >= 30
-
Hello everyone, today I gave pieces codes to you as holiday presents from me to all who read this topic. For those who does not liked Java syntax where you have to write access modes too often like me. According my topic was written for spending more hours to exploring new Android API SDK >= 30 in here -> Facing Problem with New Window API Android SDK => 30 using QJniObject
Disclaimer: This code is written by using QT6 so if you use QT5 you must changing their variables. I am not responsibility if this codes halted your apps, I am not celebrating christmas and new year eve because I am muslim, so do not said merry christmas or happy new year to me, by giving any thanks is enough to me.
This code function is to determining the navigation bar visibility :
QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); QJniObject decorview = window.callObjectMethod("getDecorView", "()Landroid/view/View;"); QJniObject inset = decorview.callObjectMethod("getRootWindowInsets", "()Landroid/view/WindowInsets;"); int navbarinsets = QJniObject::callStaticMethod<jint>( "android/view/WindowInsets$Type", "navigationBars","()I"); bool isNavbarVisible = inset.callMethod<jboolean>("isVisible","(I)Z", navbarinsets);
This code function is to hide the navigation bar and gave fadding effect when navigation bar is hiding :
QJniObject insetcontroller = decorview.callObjectMethod( "getWindowInsetsController", "()Landroid/view/WindowInsetsController;"); int navbarinsets = QJniObject::callStaticMethod<jint>( "android/view/WindowInsets$Type", "navigationBars","()I"); int systembar = 0x00000000 | 0x00000001; insetcontrol.callMethod<void>("hide","(I)V", navbarinsets); insetcontrol.callMethod<void>("setSystemBarsBehavior","(I)V", systembar);
This code function is to grant all files access permission :
bool value = QJniObject::callStaticMethod<jboolean>( "android/os/Environment", "isExternalStorageManager"); if(value == false){ QJniObject filepermit = QJniObject::getStaticObjectField( "android/provider/Settings", "ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", "Ljava/lang/String;"); //you must changing the YOURPKGNAME at below QJniObject pkgName = QJniObject::fromString("package:YOURPKGNAME"); QJniObject parsedUri = QJniObject::callStaticObjectMethod( "android/net/Uri", "parse","(Ljava/lang/String;)Landroid/net/Uri;", pkgName.object<jstring>()); QJniObject intent("android/content/Intent", "(Ljava/lang/String;Landroid/net/Uri;)V", filepermit.object<jstring>(),parsedUri.object()); QtAndroidPrivate::startActivity(intent, 0); }
This was hack when android applied SAF (Storage Access Framework) QT also available method which return as uri only, hope this help you to facing the problem, you also need an uri parser to proceed a file on Linux userland from Android userland.
QUrl url = QFileDialog::getOpenFileUrl(View, "Send file"); QString file = url.toString();
-
thx for this . will come back later when I'm on Qt6
-
@ekkescorner you don't need to waiting until you are using QT6. Read the disclaimer on this post. This code is also works on QT5 but you must changing their variables first.
-
@Kafabih can't seem to get read and write to file working with your provided code is there something i am missing in that ?????? i have just copy passed your code replaced "package:YORRRPKGNAME" with my own ........ two days of work and still no solution to the problem. i can read a text file but not save a file
thx in advance