How to receive volume changed events for the voice (in-call) stream type?

前端 未结 2 1270
死守一世寂寞
死守一世寂寞 2020-12-02 00:37

I\'m trying to register a broadcast receiver to handle the VOLUME_CHANGED_ACTION event, only for the volume_voice stream type (which I empirically

相关标签:
2条回答
  • 2020-12-02 00:47

    I'm trying to register a broadcast receiver to handle the VOLUME_CHANGED_ACTION event

    There is no VOLUME_CHANGED_ACTION in the Android SDK.

    The label EXTRA_VOLUME_STREAM_TYPE is hidden, so I have used the explicit string "android.media.EXTRA_VOLUME_STREAM_TYPE" instead.

    There is no EXTRA_VOLUME_STREAM_TYPE in the Android SDK.

    Is there a more robust way to handle VOLUME_CHANGED_ACTION for volume_voice stream types?

    There is no VOLUME_CHANGED_ACTION in the Android SDK.

    Whatever you are trying to do is undocumented, unsupported, may not work on any given version of Android (past/present/future), and may not work on any given device (since manufacturers can change anything that is not in the SDK). It will never be "robust", by definition.

    0 讨论(0)
  • 2020-12-02 01:03

    My temporary (and probably bad) workaround is to catch the ArrayIndexOutOfBoundsException, and in the catch block to test the stream type to have value of Settings.System.VOLUME_SETTINGS.length.

    This is the best I have so far. I don't know if it might catch other stream types as well, and also if it is going to work on other Android versions than 2.3.3-2.3.5.

    0 讨论(0)
提交回复
热议问题