获取
E / android.media.AudioRecord:用户权限被拒绝!
运行android 7.0.0的Samsung S8出现错误。但是,在moto g3(android版本7.1.1)和一个中没有看到此错误 加3(安卓版8.0.0)。我曾尝试过版本为7.1.1的三星手机(也出现了相同的错误。) 目标sdk版本是25
记录下面的日志:_id
答案 0 :(得分:0)
使用PermissionChecker.checkCallingOrSelfPermission应该可以完成工作。
get_queryset() missing 1 required positional argument: 'request'
答案 1 :(得分:0)
在创建startRecording()
实例后,以一定的延迟启动AudioRecord
类的Audiorecord
方法:
public void start() {
// Stop recording if it is currently ongoing.
stop();
// Try to create a new recording session.
mAudioRecord = createAudioRecord();
CommonMethods.printLog(TAG, mAudioRecord.toString());
if (mAudioRecord == null) {
throw new RuntimeException("Cannot instantiate VoiceRecorder");
}
// Start recording.
if (getDeviceManufacturer().contains("samsung")) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
new CountDownTimer(100, 50) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
mAudioRecord.startRecording();
// Start processing the captured audio.
mThread = new Thread(new ProcessVoice());
mThread.start();
}
}.start();
}
});
}
}
private AudioRecord createAudioRecord() {
for (int sampleRate : SAMPLE_RATE_CANDIDATES) {
final int sizeInBytes = AudioRecord.getMinBufferSize(sampleRate, CHANNEL, ENCODING);
if (sizeInBytes == AudioRecord.ERROR_BAD_VALUE) {
continue;
}
final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
sampleRate, CHANNEL, ENCODING, sizeInBytes);
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
mBuffer = new byte[sizeInBytes];
return audioRecord;
} else {
audioRecord.release();
}
}
return null;
}
private String getDeviceManufacturer() {
String deviceManufacturer = android.os.Build.MANUFACTURER;
return deviceManufacturer;
}
答案 2 :(得分:0)
三星(以及其他手机)不允许调用“ RECORD_AUDIO
”之类的“危险”动作,除非它们来自您的进程所拥有的线程。这意味着,如果您尝试从Binder线程或其他IPC线程进行调用,则即使您的应用程序已接受所有相关权限,请求也会失败,并显示权限错误。这是一个很好的安全措施,但是他们可能会添加一些日志记录b / c,目前尚不清楚失败的原因。
尝试通过Handler()
或使用Activiy.runOnUiThread()
生成另一个线程并在那里调用startRecord()
。