Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android app crush #42

Open
boulbaba opened this issue Aug 13, 2018 · 3 comments
Open

android app crush #42

boulbaba opened this issue Aug 13, 2018 · 3 comments

Comments

@boulbaba
Copy link

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

@HarrSolo
Copy link

HarrSolo commented Sep 1, 2018

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 !

@gifari98
Copy link

@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.

@HarrSolo
Copy link

@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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants