OmRecorder icon indicating copy to clipboard operation
OmRecorder copied to clipboard

android app crush

Open boulbaba opened this issue 6 years ago • 3 comments

so i have writen a simple code based on your project to record .wav for multiple users but whenever i try the application everything is fine untel i clic on on the imageview containing the photo of mic to record its just crushes ?

any solution ??

this is a link for my question in stackoverflow too https://stackoverflow.com/questions/51821888/record-wav-format-file-in-android-using-omrecorder

plz anwser me asap ??

boulbaba avatar Aug 13 '18 17:08 boulbaba

That's because the permission is not obtained to write to the directory ADD the following code

private void requestPermission() { ActivityCompat.requestPermissions(MainActivity.this, new String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO}, RequestPermissionCode); }

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case RequestPermissionCode:
            if (grantResults.length > 0) {
                boolean StoragePermission = grantResults[0] ==
                        PackageManager.PERMISSION_GRANTED;
                boolean RecordPermission = grantResults[1] ==
                        PackageManager.PERMISSION_GRANTED;

                if (StoragePermission && RecordPermission) {
                    Toast.makeText(MainActivity.this, "Permission Granted",
                            Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
                }
            }
            break;
    }
}




public boolean checkPermission() {
    int result = ContextCompat.checkSelfPermission(getApplicationContext(),
            WRITE_EXTERNAL_STORAGE);
    int result1 = ContextCompat.checkSelfPermission(getApplicationContext(),
            RECORD_AUDIO);
    return result == PackageManager.PERMISSION_GRANTED &&
            result1 == PackageManager.PERMISSION_GRANTED;
}

and in the onCreate() method add this

if(!checkPermission()) { requestPermission(); }

DO NOT FORGET to add permission in Manifest.xml too like in the description !

HarrSolo avatar Sep 01 '18 17:09 HarrSolo

@HarrSolo i follow your instruction, but i got an error with the RequestPermissionCode, what actually is that? a variable? image it says cannot resolve symbol.

gifari98 avatar Apr 14 '19 15:04 gifari98

@HarrSolo i follow your instruction, but i got an error with the RequestPermissionCode, what actually is that? a variable? image it says cannot resolve symbol.

Yes its an int.

  • Replace RequestPermissionCode with a number like 99 or
  • add static Integer RequestPermissionCode = 99;

HarrSolo avatar Apr 14 '19 18:04 HarrSolo