2
我已实施类似于this的代码。我在日志中发出噪音警报,但无论外界发生什么样的噪音,它总是会给出32639
或-32640
。Android麦克风在新设备上不断提供32639或-32640
short[] buffer = new short[minSize];
boolean thresholdMet = false;
int threshold = sliderThreshold.getProgress();
ar.read(buffer, 0, minSize);
//Iterate through each chunk of amplitude data
//Check if amplitude is greater than threshold
for (short s : buffer) {
if (Math.abs(s) > threshold) {
thresholdMet = true;
Log.w("NoiseThreshold", String.valueOf(s));
break;
}
}
我已经测试了三款手机(其中没有一个是植根):
- 三星Galaxy S3(API 19)
- 的HTC One M9(API 23)
- 三星Galaxy S7(API 24)
它适用于S3,但不适用于其他。我试过在HTC上使用Sensor Sense,它不适用于麦克风传感器。然而,它曾经工作过,现在似乎在图形视图中每隔五秒左右检测一次样本。
奇怪的是,麦克风仍然可以在发生故障的手机上进行电话和录像。
你检查,如果麦克风权限设置:设置>应用程序授予的权限? – rupps
@rupps是的,许可授予所有设备 – FracturedRetina
哈哈好..只是一个疯狂的猜测,有时棉花糖是挑剔的某些权限。 – rupps