I am developing a mobile application using Ionic and Cordova and would like to play a sound based on device Ringer Mode status
.
Is there any way I can get to know the device Ringer mode status:
vibration
silent
normal
I found an example for Android here.
The only plugin I was able to find is this one and it is only available for iOS. I haven't been able to test it myself, so I would recommend you take a look if you are interested in iOS.
Unfortunately I was not able to find anything for Android. So I took this as a nice opportunity to look into creating my own Cordova plugin. I have not extensively tested it yet and it only works for Android, but I think it can be used as a starting point for you and others.
You can find the repository here. Please feel free to fork or contribute to the existing repository. The plugin can be installed by running the following command: cordova plugin add https://github.com/RasimKanca/cordova-plugin-ringermode.git
. And you can use it like so:
plugins.ringerMode.getRingerMode(function(ringerMode) {
console.log("The current ringerMode is:" + ringerMode);
});
This method will return one of these three options: RINGER_MODE_VIBRATE
, RINGER_MODE_NORMAL
or RINGER_MODE_SILENT
.
I looked into doing the same for iOS, however there doesn't seem to be a official way of detecting the ringer status on iOS, as described here and here. If anyone could shed some light into how this can be achieved on iOS, feel free to comment and I'd be happy to add it to the plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With