From 4e848fc50287549204be64b0dde2bdbfa52b8a2c Mon Sep 17 00:00:00 2001 From: HBiSoft Date: Thu, 28 Oct 2021 10:33:59 +0200 Subject: [PATCH] Fix issue #91 --- .../hbrecorderexample/MainActivity.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java index a0931ab..482dcfa 100644 --- a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java +++ b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java @@ -201,9 +201,16 @@ private void setOnClickListeners() { public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //first check if permissions was granted - if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO) && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE)) { - hasPermissions = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) { + hasPermissions = true; + } + } else { + if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO) && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE)) { + hasPermissions = true; + } } + if (hasPermissions) { //check if recording is in progress //and stop it if it is @@ -557,16 +564,21 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } break; case PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE: - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { hasPermissions = true; - //Permissions was provided - //Start screen recording - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - startRecordingScreen(); - } + startRecordingScreen(); } else { - hasPermissions = false; - showLongToast("No permission for " + Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + hasPermissions = true; + //Permissions was provided + //Start screen recording + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + startRecordingScreen(); + } + } else { + hasPermissions = false; + showLongToast("No permission for " + Manifest.permission.WRITE_EXTERNAL_STORAGE); + } } break; default: