Android 判断耳机是否插入
2016-09-20 13:44
387 查看
//给广播绑定响应的过滤器 IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.HEADSET_PLUG"); HeadsetReceiver headsetReceiver = new HeadsetReceiver(); registerReceiver(headsetReceiver, intentFilter);
//自己定义的广播接收器
public class HeadsetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.hasExtra("state")) {
if (0 == intent.getIntExtra("state", 0)) {
Toast.makeText(context, "耳机未插入", Toast.LENGTH_SHORT).show();
} else if (1 == intent.getIntExtra("state", 0)) {
Toast.makeText(context, "耳机已插入", Toast.LENGTH_SHORT).show();
}
}
}
}
相关文章推荐
- android 判断耳机是否插入的几种方式
- android 判断耳机是否插入的几种方式
- android 判断耳机是否插入的几种方式
- android动态注册判断耳机(headset)是否插入
- android 检测耳机是否插入
- android 检测耳机是否插入
- [学习记录]android 检测耳机是否插入
- Android 判断耳机是否存在
- android 检测耳机是否插入
- android 检测耳机是否插入
- iOS判断是否插入耳机
- 判断设备是否插入耳机
- iOS判断耳机是否插入
- 判断设备是否插入耳机
- android 检测耳机是否插入
- android 检测耳机是否插入
- 腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
- 判断设备是否插入耳机
- Android下,判断网线是否插入的方法