在广播接收器里截获蓝牙配对的广播
....
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;
}
}