Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the ringer status / silent status of a device using Cordova?

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.

like image 761
Ameer Hamza Avatar asked Jul 19 '16 07:07

Ameer Hamza


Video Answer


1 Answers

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.

like image 200
Dexter Avatar answered Oct 26 '22 18:10

Dexter