Skip to content

Latest commit

 

History

History
138 lines (109 loc) · 6.01 KB

File metadata and controls

138 lines (109 loc) · 6.01 KB

Volume

This module is used to change or obtain the existing volume states of the device.

Functions

The volume module contains the following functions.

    indexOf(String type)
    indexTo(String type, int index)
    silence()
    normalize()
    vibrate() 

Permissions

For API levels below 23, no permission is required to use all the functions in this module. In addition, to call indexOf() and indexTo() functions of the module, no permission is required for all API levels released till date (API level 28). However, for API level 23 and above, users should grant access to Do Not Disturb configuration in order to make a successful calls to the silence(), normalize() and vibrate() functions. As a result, the following permission should be added in the AndroidManifest.xml file outside the application tag.

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

Description

The above functions are used to perform the following activities.

🔷 indexOf(String type):

is used to obtain the current, minimum and maximum volume indices of the audio stream of the device as specified by type parameter. The possible values for type are: "alarm" , "music" , "notification" , "ring" , "voicecall" and "system".

Sample code snippet
            import { Volume } from "react-native-system-applications";
            ...
            ...
            ...
            _getAudioVolume = () => {
                Volume.indexOf("system").then((res) => {
                    console.log(res); // see the output format below
                }).catch((err) => {
                    console.log(err);
                });
            } 
Sample result

Call to _getAudioVolume() may result in the following log output depending on the type of the divice used and the current volume state of the system stream of the device. For unseccessful requests, a promise rejection will be sent back.

                {
                  "minimum": 0, 
                  "maximum": 15, 
                  "current": 5 
                }

🔷 indexTo(String type, int index):

is used to set the current index of the audio stream of the device as specified by the type parameter. The possible values for type are: "alarm" , "music" , "notification" , "ring" , "voicecall" and "system". Note that if the value of index parameter is not between the minimum and maximum audio indices of the device, the intended outcome may not be achieved. The minimum and maximum indices can be requested by calling the above function.

Sample code snippet
            import { Volume } from "react-native-system-applications";
            ...
            ...
            ...
            _setAudioVolume = () => {
                Volume.indexTo("music", 7).then((res) => {
                    // do something
                }).catch((err) => {
                    console.log(err);
                });
            } 

Call to _setAudioVolume() sets the audio index of the music stream to 7 for successful requests or a promise rejection if something goes wrong.

🔷 silence():

is used to set the ringer mode of the device to silent with no vibration.

Sample code snippet
            import { Volume } from "react-native-system-applications";
            ...
            ...
            ...
            _silenceRinger = () => {
                Volume.silence().then((res) => {
                    // do something
                }).catch((err) => {
                    console.log(err);
                });
            } 

Call to _silenceRinger() sets the ringer mode of the device to silent with no vibration for successful requests or a promise rejection if something goes wrong.

🔷 vibrate():

is used to set the ringer mode of the device to a mode that will be silent and will vibrate.

Sample code snippet
            import { Volume } from "react-native-system-applications";
            ...
            ...
            ...
            _vibrateRinger = () => {
                Volume.vibrate().then((res) => {
                    // do something
                }).catch((err) => {
                    console.log(err);
                });
            } 

Call to _vibrateRinger() sets the ringer mode of the device to silent but with vibration for successful requests or a promise rejection if something goes wrong.

🔷 normalize():

is used to set the ringer mode of the device to a mode that may be audible and may vibrate. It will be audible if the volume before changing out of this mode was audible. It will vibrate if the vibrate setting is on.

Sample code snippet
            import { Volume } from "react-native-system-applications";
            ...
            ...
            ...
            _normalizeRinger = () => {
                Volume.normalize().then((res) => {
                    // do something
                }).catch((err) => {
                    console.log(err);
                });
            } 

Call to _normalizeRinger() sets the ringer mode of the device to normal for successful requests or a promise rejection if something goes wrong.