我想注册一个广播接收器处理 VOLUME_CHANGED_ACTION
事件,只为 volume_voice
流类型(这是我经验看是在指数 0
Settings.System.VOLUME_SETTINGS
)。
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
).
标签 EXTRA_VOLUME_STREAM_TYPE
是隐藏的,所以我使用了明确的字符串android.media.EXTRA_VOLUME_STREAM_TYPE
而不是。这一切都正常工作在Android 2.3.4(得值 0
为 volume_voice
如预期),但在2.3.5这额外的存放值是 10
,其中给出了一个 ArrayIndexOutOfBoundsException异常
在 Settings.System。 VOLUME_SETTINGS
。
此外,我看到 volume_voice
仍是 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
.
有没有更可靠的方法来处理 VOLUME_CHANGED_ACTION
为 volume_voice
流类型?
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?
我的临时(也可能是坏的)解决办法是捕捉 ArrayIndexOutOfBoundsException异常
,并在catch块测试流类型具有的价值 Settings.System.VOLUME_SETTINGS.length
。
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
.
这是最好的,我有这么远。我不知道这是否会赶上其他流类型为好,同时如果是去工作,其他Android版本比2.3.3-2.3.5。
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.
上一篇:如何通过对象的活动?对象