Skip to content

Commit

Permalink
Fix issue #91
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Oct 28, 2021
1 parent b34e2b8 commit 4e848fc
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4e848fc

Please sign in to comment.