Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

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

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 see to be index 0 in Settings.System.VOLUME_SETTINGS).

The label EXTRA_VOLUME_STREAM_TYPE is hidden, so I have used the explicit string "android.media.EXTRA_VOLUME_STREAM_TYPE" instead. It all worked fine on Android 2.3.4 (got value 0 for volume_voice as expected), but on 2.3.5 the value that this extra holds is 10, which gives an ArrayIndexOutOfBoundsException on Settings.System.VOLUME_SETTINGS. Moreover, I see that volume_voice is still index 0 in Settings.System.VOLUME_SETTINGS.

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

Edit Or any other way to do what the title asks for?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...