I've implemented code similar to this. I have a noise alert go off in the Log, but it always gives 32639
or -32640
regardless of what kind of noise is going on outside.
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; } }
I've tested it on three phones (none of which are rooted):
- Samsung Galaxy S3(API 19)
- HTC One M9(API 23)
- Samsung Galaxy S7(API 24)
It works on the S3, but not the others. I've tried using Sensor Sense on the HTC and it doesn't work for the mic sensor. However, it used to work, and now seems to detect one sample every five seconds or so in the graph view.
Oddly enough, the microphone still works fine for phone calls and video recording on the malfunctioning phones.
1 Answers
Answers 1
You said it works on S3, which is API 19 and doesn't on those with API>=23. So, it's possible that you have a problem with runtime permissions introduced in API 23.
New behaviour (for "old apps" which use static permission model) is to return dummy data if runtime permission is not granted.
Check out this answer: Request permission for microphone on Android M
0 comments:
Post a Comment