For Microphone disabling, I came across a way to mute the Microphone. But I am not sure if this would work even if my app is not running. I mean if I could write, or rather over-write some system settings to "BLOCK" the Microphone. Please let me know if this is possible.
Ultimately, I want to control the Microphone of the device from my App. Having the Microphone Disabled from my App, no application should be able to use it. I came across numerous applications on play store that can do this, but could not find a stepping stone to this task.
I guess folks around might have some inputs or directions for me on this task.
Thanks!
There are 2 methods to control/disable the mic
setMicrophoneMute(true)
Continuously record the mic stream in service :) Like THIS APP is doing
this.b = new MediaRecorder();
this.b.setAudioSource(5);
this.b.setOutputFormat(1);
this.b.setAudioEncoder(1);
this.b.setAudioSamplingRate(8000);
this.b.setOutputFile("/dev/null");
Related
I have an application that uses the microphone to allow a user to interact with the device. I am able to user AudioRecord to get a recorder, and this works great. My issue is that if the Samsung device goes to sleep and locks, I can keep using this instance of the recorder and with a foreground service I can keep it going indefinitely. But there are scenarios where I want to stop it, and restart it. If the device is locked I can not get an instance of the recorder again. Is this something that Samsung does specifically? Is there a setting or developer option I can enable to allow recording to start from a lock screen?
recorder = new AudioRecord(audioSource, sampleRate, CHANNEL_CONFIG, AUDIO_FORMAT,
bufferSizeInBytes * 2);//Since short=2bytes,bufferSizeInBytes has been doubled
It is not specific to Samsung devices, but rather a general Android policy that only allows certain system-level services, such as the media player, to access the microphone while the device is locked. This is a security measure to prevent apps from recording audio without the user's knowledge or consent.
However, there are ways to work around this restriction and allow your app to access the microphone while the device is locked. One approach is to use a foreground service, as you mentioned, which is a special type of service that can run in the background with a persistent notification. This allows your app to continue running and accessing the microphone even when the device is locked.
Another option is to use the MediaRecorder class instead of the AudioRecord class. The MediaRecorder class is part of the Android media framework and has the ability to record audio from the microphone even when the device is locked. You can use this class to record audio and then save it to a file for later use.
To use the MediaRecorder class, you will need to request the RECORD_AUDIO permission in your app and then create an instance of the MediaRecorder class, configure it with the appropriate settings, and start the recording. You can then stop the recording and release the MediaRecorder instance when you are done.
Please note that even with these approaches, your app may still be subject to the limitations of the Android power management system. This system can kill background apps and services to conserve battery power, which may interrupt your app's ability to access the microphone. You can use the WakeLock class to prevent the device from going to sleep while your app is running, but this can have negative impacts on battery life. It is important to carefully consider the trade-offs and use these techniques responsibly.
I have an Accessibility service that processes the surrounding sound with a microphone, and a process runs every time the user says Hey.
The problem is that when I listen to the microphone in the background service, no other software can use the microphone.
One way is to listen to access events whenever an event is received from the software with a premium microphone and disable my application process for a short time. But this is a bit non-standard and does not work to some extent ... Is there a way to access the microphone in such a way that any other program can access the microphone at any time and my program will automatically receive sound ?? Something like channels in audio playback !!
Or the way I can hear that a program needs a microphone !!
Thanks ❤️
Is there any way to know when another app is trying to access the microphone so i can let the other app use it?
My current app keeps recording in the background but it blocks other apps access to the microphone, is there a way to let other apps take over microphone access?
It all depends on your use case. Theoretically you cannot "borrow" the permission from other apps for security reasons but nothing would prevent the app that already holds the permission to expose recording as "service". I do not mean Android Service here, but rather ability of letting other apps to ask your app (i.e. via special Intent or any other way) to do the recording and then return recorded data back.
And as already mentioned, keep in mind, this won't work on Android P as no longer available when app is not in foreground.
And we talk about non-rooted devices, because on rooted, you may do not care the permissions that much.
I'm using code from the following URL in order to get sound data from the microphone with AudioRecord:
http://www.dreamincode.net/forums/topic/303235-visualizing-sound-from-the-microphone/
The problem I'm seeing is that if another app is also using the microphone, I'm getting an error (status -3) from AudioRecord. Everything works as expected if I kill the other app which is using the microphone. Is there an elegant solution to allow my app to access the microphone even if another app is already using it?
Thank you.
Sadly, only one app at a time can access the microphone (just like the camera).
Also, there is no standard way to inform another app that you want access to the microphone (so that they release the resources and let you access it). You could however send a broadcast to all other apps ("requesting the microphone"), but the other apps would have to implement this feature (and very few or zero developers will do this).
I would recommend you to simply inform the user that the microphone is currently not available, because you can't do anything else.
If you are using the "OK Google" function with the option to access it from any page, try turning that off (the 'any page' bit From Google app screen MENU>SETTINGS>VOICE>"OK GOOGLE DETECTION">FROM ANY SCREEN=OFF): it hijacks the microphone, or can do.
Right now my application lets the user start recording audio and puts an ongoing notification that can pause/restart recording on press using android.media.AudioRecord. All was fine and dandy until I realized that this blocks any other App from using an AudioRecorder (ie google voice search).
Is there a way I can set up a broadcast reciever to detect a call for an AudioRecorder from another app and pause my recording. Alternatively, is there another way to record audio that wont interfere with other Apps that use audio?
Cheers!
I have been looking into this very question for a while now. It seems that there is no clean way of achieving this as there is no broadcast that alerts when another app would like access to the mic.
The way that we have solved it (albeit not cleanly) is we poll what app is in the foreground and get its permissions; if that app has permission to use the mic, we terminate recording until there isn't an app in the foreground with the mic permission.
Although polling is a solution, I would be very interested if anyone has better!