我有设置流量和服务的方法,其中包含Hadler以检查此更改
设置流的方法:
private setStreams(Context context)
{
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_RING, ringerVol, 0);
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, notifVol, 0);
am.setStreamVolume(AudioManager.STREAM_MUSIC, mediaVol, 0);
am.setStreamVolume(AudioManager.STREAM_ALARM, alarmVol, 0);
am.setStreamVolume(AudioManager.STREAM_SYSTEM, systemVol, 0);
am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, incallVol, 0);
am.setStreamVolume(6, btVol, 0);
//some other code
}
Serivce:
public class SystemSettingsChangeObserverService extends Service {
private ContentObserver observer;
private static Context context;
@Override
public void onCreate(){
super.onCreate();
context = this;
observer = new ContentObserver (new Handler()) {
@Override
public boolean deliverSelfNotifications() {
return super.deliverSelfNotifications();
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//here I check new values of streams
}
}
...
问题是,onChange在setStreams方法中的“其他代码”之后调用,而不是在每个流的setStreamVolume之后调用。我需要这个,因为我需要知道我的应用程序内部或其他方式是否更改了卷。谢谢。
答案 0 :(得分:0)
通过在SharedPreferences中放置布尔键“fromApp”并在SystemSettingsChangeObserverService中检查它来解决,然后将键设置为false