I need to call setVolumeControlStream
from a service that plays some sound via STREAM_SYSTEM
.
Obviously in an Activity that is no problem, but how can I do this with a service?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
From the looks of it, this isn't possible the way you are trying to do it.
As said in the android reference
The suggested audio stream will be tied to the window of this Activity
Hence with a service that has no activity, there is no window to tie the audio stream to.
However, It looks like you should be able to receive media key events (including volume keys) from a broadcaster as shown here which would allow you to change your service volume without an activity being visible.
回答2:
I think this library can provide you what you need:
http://code.google.com/p/media-volume-control/