Skip to content Skip to sidebar Skip to footer

StartRecording() Called On An Uninitialized AudioRecord

i am trying to record voice call on android. I am using AudioRecord class/api of android to perform this. But for some reason AudioRecord is not able to record voice call on some d

Solution 1:

You need to explicitly ask for:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

on all devices after Lollipop so API lvl 23+

if (ContextCompat.checkSelfPermission(thisActivity, 
    Manifest.permission.RECORD_AUDIO)
        != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.RECORD_AUDIO},
            1234);
}

and then override:

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1234: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                initializePlayerAndStartRecording();

            } else {
                Log.d("TAG", "permission denied by user");
            }
            return;
        }
    }
}

Post a Comment for "StartRecording() Called On An Uninitialized AudioRecord"