How to detect microphone conflicts on Android

Task

When I try to use the microphone on Android, I can't record if another app is already using it. If you just can't record, it means that the sound you intend to record is flowing to the app holding the microphone if you're not careful. If VoIP apps run at the same time, the worst situation can be that the voice reaches only another person, not the person you are talking to. .. ..

Thing you want to do

Detects that your app cannot use the microphone and stops recording.

How to respond

The flow is as follows when recording. AudioRecord

AudioRecord audioRecord = new AudioRecord(,,,,);
audioRecord.setRecordPositionupdateListener(new AudioRecord.OnRecordPositionupdateListener() {
    //Processing for each frame
    @Override
    public void onPeriodicNotification(AudioRecord recorder) {
        audioRecord.read();
    }
});
audioRecord.setPositionNotificationPeriod();
audioRecord.startRecording();
audioRecord.read();
・
・
・
audioRecord.stop();

However, it seems that none of the functions return an error, even if other apps are using the microphone. .. ..

However, there was a difference with and without competition for microphone usage. If you can't get the microphone, it doesn't seem to call onPeriodicNotification, which is a callback for frame-by-frame processing.

Therefore, if onPeriodicNotification is not called after a certain period of time, it seems that it can be determined that the microphone is acquired by another app.

Confirmed contents / environment

** Contents ** Make sure onPeriodicNotification is not called during a call on Line, Facebook messenger environment Nexus 6 (7.1.1) , Nexus 7 (6.0.1)

Remarks

――Please let me know if there is a better way! ――Please let me know if you cannot detect it by this method!

Recommended Posts

How to detect microphone conflicts on Android
How to "hollow" View on Android
[Android] How to detect volume change (= volume button press)
How to resolve Git conflicts
How to deploy on heroku
How to deploy Laravel on CentOS 7
[Java] How to update Java on Windows
How to install ImageMagick on Windows 10
How to use Ruby on Rails
How to deploy Bootstrap on Rails
How to run JavaFX on Docker
How to use Bio-Formats on Ubuntu 20.04
How to install MariaDB 10.4 on CentOS 8
Rails on Tiles (how to write)
How to install WildFly on Ubuntu 18.04
How to build vim on Ubuntu 20.04
[Android] How to make Dialog Fragment
How to call with One Touch (without confirmation) on Android (Java)
How to check Java installed on Mac
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
How to use Apache Derby on Eclipse
[Ruby on Rails] How to use CarrierWave
Sample to display (head-up) notifications on Android
[Android] How to deal with dark themes
How to install Eclipse (Photon) on Mac
How to publish an application on Heroku
How to install production Metabase on Ubuntu
How to switch Java versions on Mac
How to install beta php8.0 on CentOS8
How to change the timezone on Ubuntu
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to install kafkacat on Amazon Linux2
How to send push notifications on AWS
How to use ExpandableListView in Android Studio
[Android] How to turn the Notification panel on and off using StatusBarManager
Scheduled to support Reiwa on Android 11 as standard
[Ruby on Rails] How to display error messages
How to deploy a container on AWS Lambda
[Android] How to convert a character string to resourceId
How to configure ubuntu to be used on GCP
How to add / remove Ruby on Rails columns
How to make rbenv recognize OpenSSL on WSL
How to install network drivers on standalone Ubuntu
How to save images on Heroku to S3 on AWS
How to install NVIDIA driver on Ubuntu 18.04 (Note)
How to deploy
Notes on how to use each JUnit Rule
How to make Unity Native Plugin (Android version)
Note how to rollback Mysql deployed on Heroku
How to install multiple JDKs on Ubuntu 18.04 LTS
[Rails MySQL] How to reset DB on heroku
[Java] 4 steps to implement splash screen on Android
How to write React Native bridge ~ Android version ~
[Ruby on Rails] How to install Bootstrap in Rails
How to build a Pytorch environment on Ubuntu
[Ruby on Rails] How to use session method
[Java] Memo on how to write the source
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
Notes on how to create Burp Suite extensions