【发布时间】:2012-02-10 11:21:02
【问题描述】:
我有一个注册到 android.provider.Settings.System 的 ContentObserver,它应该观察任何音量的变化。单击硬件音量按钮时会按预期通知,但当我通过 AudioManager.setStreamVolume 或 AudioManager.adjustStreamVolume 更改音量时不会通知。
这是我的 ContentObserver 的样子:
// this is a Service
this.getApplicationContext().getContentResolver().registerContentObserver(
android.provider.Settings.System.CONTENT_URI,
true, new ContentObserver(new Handler()) {
public void onChange(boolean selfChange) {
Log.d("ContentObserver", "got notified");
}
});
这里是我对 AudioManager.adjustStreamVolume 的调用:
// this.context is the activities context
this.context.getSystemService(Context.AUDIO_SERVICE).adjustStreamVolume(
AudioManager.STREAM_RING, AudioManager.ADJUST_LOWER,
AudioManager.FLAG_SHOW_UI);
我已阅读 this 和 that 帖子以及 AudioManager 和 Settings.System 文档,但找不到使用音量按钮更改音量时通知观察者但使用音量按钮更改音量时没有通知的原因音频管理器。
感谢您的帮助!
【问题讨论】:
标签: java android android-emulator