acomminos / Jumble

An Android service implementation of the Mumble protocol.
GNU General Public License v3.0
90 stars 51 forks source link

Audio recording and permissions in Marshmallow #17

Open janekp opened 8 years ago

janekp commented 8 years ago

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:

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 7 years ago

+1, I ran into this today.