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 to catch onRequestPermissionsResult for QtActivity in Android 6?
Forum Updated to NodeBB v4.3 + New Features

How to catch onRequestPermissionsResult for QtActivity in Android 6?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 1.9k Views 3 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.
  • G Offline
    G Offline
    Gourmet
    wrote on 23 Nov 2017, 17:13 last edited by Gourmet
    #1

    To properly process permissions for Android M I call requestPermissions(...) Android method. It works in my app and shows dialogs with requests. But I cannot catch user's response cause my onRequestPermissionsResult() method is newer called. Here is my simplified code:

    public class PlayControl extends QtActivity
    {
    .....
        public static boolean requestPermission()
        {
            boolean p = true;
            if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M )
            {
                Activity a = QtNative.activity();
                Context c = a.getApplicationContext();
                if( c.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED )
                {
                    ActivityCompat.requestPermissions(a, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                                        Manifest.permission.READ_EXTERNAL_STORAGE,
                                                        Manifest.permission.RECORD_AUDIO }, 1);
                    p = false;
                }
            }
            return p;
        }
    
        public void onRequestPermissionsResult(int requestCode, String permissions[], int grantResults[])
        {
            NativeCall.permissionsGranted();
        }
    }
    

    The NativeCall itself works properly - it is used in other parts of code. But NativeCall.permissionsGranted(); is newer called. I checked this with some other code and found that onRequestPermissionsResult() is newer called.

    How to workaround this? Is there a way for Qt application get user's response to permissions requests?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      ekkescorner
      Qt Champions 2016
      wrote on 24 Nov 2017, 16:16 last edited by
      #2

      have you tried the workarounds here ?
      https://bugreports.qt.io/browse/QTBUG-50759?focusedCommentId=366042&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-366042

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gourmet
        wrote on 25 Nov 2017, 14:27 last edited by
        #3

        No, I cannot use this. I build app with Qt 5.6 historically and cannot quickly change version.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Aptem
          wrote on 1 Mar 2021, 20:23 last edited by
          #4

          eb5b80a0-e542-4647-8fa6-e5a335fbfd41-image.png

          It work after import androidx.appcompat.app.AppCompatActivity;

          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