Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to catch onRequestPermissionsResult for QtActivity in Android 6?



  • 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?


  • Qt Champions 2016



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


Log in to reply