android 蓝牙 无法开启蓝牙耳机,解决 android audiorecord 蓝牙耳机 重启导致录音数据异常问题...

mAudioManager.registerMediaButtonEventReceiver(new ComponentName(

this,

MusicIntentReceiver.class));

@SuppressLint("InlinedApi")

public class MusicIntentReceiver extends BroadcastReceiver {

private static final String LOG_TAG = "jni";

private Context mContext;

private KeyService mKeyService;

@Override

public void onReceive(Context context, Intent intent) {

mContext = context;

mKeyService = new KeyService(mContext);

if (intent.getAction().equals(

android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {

Toast.makeText(context, "Headphones disconnected.",

Toast.LENGTH_SHORT).show();

Log.i(LOG_TAG, "Headphones disconnected.!");

// send an intent to our MusicService to telling it to pause the

// audio

// context.startService(new Intent(MusicService.ACTION_PAUSE));

} else if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {

Log.i(LOG_TAG, "ACTION_MEDIA_BUTTON!");

KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(

Intent.EXTRA_KEY_EVENT);

if (keyEvent.getAction() != KeyEvent.ACTION_DOWN)

return;

switch (keyEvent.getKeyCode()) {

case KeyEvent.KEYCODE_HEADSETHOOK:

case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:

// context.startService(new

// Intent(MusicService.ACTION_TOGGLE_PLAYBACK));

break;

case KeyEvent.KEYCODE_MEDIA_PLAY:

// context.startService(new Intent(MusicService.ACTION_PLAY));

break;

case KeyEvent.KEYCODE_MEDIA_PAUSE:

// context.startService(new Intent(MusicService.ACTION_PAUSE));

break;

case KeyEvent.KEYCODE_MEDIA_STOP:

// context.startService(new Intent(MusicService.ACTION_STOP));

break;

case KeyEvent.KEYCODE_MEDIA_NEXT:

// context.startService(new Intent(MusicService.ACTION_SKIP));

break;

case KeyEvent.KEYCODE_MEDIA_PREVIOUS:

// TODO: ensure that doing this in rapid succession actually

// plays the

// previous song

// context.startService(new Intent(MusicService.ACTION_REWIND));

break;

}

} else if (intent.getAction().equals(

BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {

int state = intent.getIntExtra(

BluetoothAdapter.EXTRA_CONNECTION_STATE, 0);

if (state == BluetoothAdapter.STATE_CONNECTED

) {

Log.i(LOG_TAG, "BluetoothAdapter.ACTION_CONNECTION_STATE_CONNECT");

}

else if (state == BluetoothAdapter.STATE_DISCONNECTED){

Log.i(LOG_TAG, "BluetoothAdapter.ACTION_CONNECTION_STATE_DISCONNECTED");

}

} else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

Log.i(LOG_TAG, "Intent.ACTION_BOOT_COMPLETED");

} else if (intent.getAction().equals("android.intent.action.UPDATE_SUSPEND_TIME_BY_HAND")) {

Log.i(LOG_TAG, "Intent.UPDATE_SUSPEND_TIME_BY_HAND");

} else {

// Log.i(LOG_TAG, "other intent");

}

}

4. 开启线程监控 控制录音

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值