Skip to content

dannyalbuquerque/sound_mode

 
 

Repository files navigation

sound_mode

A Flutter plugin to manage a device's sound mode on 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/sound_profiles.dart';

// Handle Platform Exceptions for devices running above Android 6.0 
try {
  await SoundMode.setSoundMode(Profiles.SILENT);
} on PlatformException {
  print('Please enable permissions required');
}
List of modes available
Mode Description
Profiles.NORMAL Sets the device to normal mode
Profiles.SILENT Sets the device to silent mode
Profiles.VIBRATE Sets 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();
}

Contributing

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

License

MIT

About

A plugin to manage device's sound mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 54.5%
  • Dart 43.2%
  • Swift 2.1%
  • Objective-C 0.2%