Audio recording and permissions in Marshmallow
janekp opened this issue · 1 comments
janekp commented
Users must explicitly give their permission inside the application to use the microphone in Android 6.0 and later. And these permission checks should happen as late as possible so the user can understand the purpose. However, these use-cases are not handled in the library.
Specifically:
- User hasn't used the microphone yet (push-to-send mode)
- User has disabled the microphone permission in System settings
Right now Jumble will simply fail with an exception. No input or output audio. I did a quick test and added additional checks to the AudioHandler.java class along with an additional method to start recording later (triggered after the user has granted the permission). Seems to work. Not sure about side-effects.
private boolean canRecordAudio() {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(mContext, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) ? false : true;
}
// Usage sample
if(canRecordAudio()) {
mInput = new AudioInput(this, mAudioSource, mSampleRate);
} else {
mInput = null;
}
// Additional checks later
pjgranahan commented
+1, I ran into this today.