Giter Site home page Giter Site logo

wanghaiyang5241 / sound_mode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tryingoutsomething/sound_mode

0.0 1.0 0.0 83 KB

A plugin to manage device's sound mode

License: MIT License

Java 47.54% Swift 5.69% Objective-C 3.18% Dart 38.84% Ruby 4.75%

sound_mode's Introduction

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

sound_mode's People

Contributors

tryingoutsomething avatar wanghaiyang5241 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.