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. Holiday gift 2022 pieces codes to facing new Android API SDK >= 30

Holiday gift 2022 pieces codes to facing new Android API SDK >= 30

Scheduled Pinned Locked Moved Mobile and Embedded
android 11api 30file managementwindowinsets
4 Posts 3 Posters 781 Views
  • 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.
  • K Offline
    K Offline
    Kafabih
    wrote on 18 Dec 2022, 03:00 last edited by Kafabih
    #1

    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();
    
    R 1 Reply Last reply 6 Mar 2023, 15:53
    2
    • E Offline
      E Offline
      ekkescorner
      Qt Champions 2016
      wrote on 18 Dec 2022, 16:14 last edited by
      #2

      thx for this . will come back later when I'm on Qt6

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      K 1 Reply Last reply 19 Dec 2022, 00:20
      0
      • E ekkescorner
        18 Dec 2022, 16:14

        thx for this . will come back later when I'm on Qt6

        K Offline
        K Offline
        Kafabih
        wrote on 19 Dec 2022, 00:20 last edited by
        #3

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

        1 Reply Last reply
        0
        • K Kafabih
          18 Dec 2022, 03:00

          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();
          
          R Offline
          R Offline
          RasmusK
          wrote on 6 Mar 2023, 15:53 last edited by RasmusK 3 Jun 2023, 15:53
          #4

          @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

          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