观察应用程序所做的卷更改

时间:2012-02-10 11:21:02

标签: java android android-emulator

我有一个注册到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);

我已阅读thisthat帖子以及AudioManagerSettings.System文档,但无法找到在更改音量时通知观察者的原因按钮,但不是用AudioManager更改它时。

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

AudioManager确实广播了一个意图

  

android.media.VOLUME_CHANGED_ACTION`

但这不是官方文件的一部分。所以这可能会在未来版本中发生变化但你可以使用这至少姜饼设备。

您可以从here

找到有关意图中的额外内容的更多信息
相关问题