android6.0蓝牙配对加入提示音

来源:互联网 发布:软件魔方怎么卸载 编辑:程序博客网 时间:2024/05/16 12:22

在广播接收器里截获蓝牙配对的广播

....

if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {

......

   Uri sound = Settings.System.DEFAULT_NOTIFICATION_URI;
                AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                int RingerMode = audio.getRingerMode();
                android.util.Log.d("zhang", "84  :   RingerMode  = "+RingerMode);
                if(RingerMode==AudioManager.RINGER_MODE_NORMAL){
                    if (sound != null){
                        Utils.startSound(sound, context);
                    }
                }



}



Utils.java:

    static void startSound(Uri sound,Context context) {


        if(mMediaPlayer==null){
        mMediaPlayer = MediaPlayer.create(context , sound);         
        }
mMediaPlayer.start();
    }


    static void stopSound() {
        if(mMediaPlayer!=null){
            mMediaPlayer.stop();
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }



0 0