如何处理麦克风静音?

时间:2013-05-20 13:58:35

标签: java android

我想使用ContentObserver来处理麦克风状态。但它不起作用。方法onChange没有任何内容。

public class MainActivity extends Activity implements OnClickListener{

    AudioManager amAudioManager;  

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        amAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        getContentResolver().registerContentObserver(
                System.getUriFor(System.MUTE_STREAMS_AFFECTED),
                false, mMuteObserver);
    }

    private ContentObserver mMuteObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);
            amAudioManager.setMicrophoneMute(false);
        }
    };

    @Override
    public void onClick(View v) {
        int id = v.getId();
        //just for test functional

        amAudioManager.setMicrophoneMute(true);

    }
}

Android清单文件权限:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />**

0 个答案:

没有答案