Android application device volume

mHvNG :

I have a few questions about an application I want to develop.

  1. I'm trying to find out if it's possible to make a feature that sets the message / ringtone volume from the device (not the application alone) to lets say 20%.

  2. Is it possible to check the volume from the device? So that I can check at all times if the volume is lower than 20%.

  3. Is it possible to make an app run 24/7, so I can always check the volume?

Android Studio and Flutter is both fine.

mHvNG :

For this project I used the volume library. This library lets you change all the different kind of volumes inside Android.

My code:

@override
  void initState() {
      super.initState();
      audioManager = AudioManager.STREAM_NOTIFICATION;
      initPlatformState();
      const fiveSec = const Duration(seconds: 15);
      timer = new Timer.periodic(fiveSec, (Timer timer) => setState(
        () {
          updateVolumes();
        }
      ));
  }

  Future<void> initPlatformState() async {
    await Volume.controlVolume(AudioManager.STREAM_NOTIFICATION);
  }

  updateVolumes() async {
    setState(() {

    });
    currentVol = await Volume.getVol;
    if (currentVol < minimumVol) {
      print('Volume needs some adjustments...');
      setVol(minimumVol);
    } else {
      print('Volume is fine!');
    }
  }

  setVol(int i) async {
    await Volume.setVol(i);
  }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521&siteId=1