sound_mode 2.0.1
sound_mode: ^2.0.1 copied to clipboard

A plugin to manage a device's sound mode for android. This plugin also supports requesting the required permissions to modify the device's sound mode for Android API 24 and above.

sound_mode #

You can get the sound mode status on IOS & Android! On Android you can also manage the device's sound mode.

Android Usage #

Add sound_mode as a dependency in your pubspec.yaml file

Add the following permission to AndroidManifest.xml for the app to appear in the 'Do Not Disturb Access' list

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

Features #

  1. Detect device's current sound mode
  2. Able to toggle between Normal, Silent & Vibrate mode
  3. Grant Do No Disturb permissions for devices above platform version Android 6.0 (API 23)

Example #

To get the device's current sound mode:

String ringerStatus = await SoundMode.ringerModeStatus;
print(ringerStatus);

To change the device's sound mode:

import 'package:sound_mode/utils/ringer_mode_statuses.dart';

// Handle Platform Exceptions for devices running above Android 6.0 
try {
  await SoundMode.setSoundMode(RingerModeStatus.silent);
} on PlatformException {
  print('Please enable permissions required');
}
List of modes available
ModeDescription
RingerModeStatus.normalSets the device to normal mode
RingerModeStatus.silentSets the device to silent mode
RingerModeStatus.vibrateSets the device to vibrate mode

For Android 6.0 and above

For devices with Android 6.0 and above, it is required for the user to grant Do No Disturb Access to set their device's sound mode.

To check if the user has granted the permissions and prompt for approval

import 'package:sound_mode/permission_handler.dart';

bool isGranted = await PermissionHandler.permissionsGranted;

if (!isGranted) {
  // Opens the Do Not Disturb Access settings to grant the access
  await PermissionHandler.openDoNotDisturbSetting();
}

iOS Usage #

Currently, it is possible to get the device's ringer mode status. For iOS, the following lines of code can be added to use it in flutter

ringerStatus = await SoundMode.ringerModeStatus;

List of ringerModeStatus statuses #

StatusDescription
RingerModeStatus.unknownDon't know the status
RingerModeStatus.normalDevice is in normal mode
RingerModeStatus.silentDevice is in silent mode
RingerModeStatus.vibrateDevice is in vibrate mode

Contributing #

Feel free to edit the plugin and submit a pull request or open an issue on github to leave a feedback

License #

MIT

7
likes
110
pub points
87%
popularity

A plugin to manage a device's sound mode for android. This plugin also supports requesting the required permissions to modify the device's sound mode for Android API 24 and above.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on sound_mode