博客
关于我
监听有线/蓝牙耳机的插入与拔出,电话的状态及拦截-Android
阅读量:215 次
发布时间:2019-02-26

本文共 1942 字,大约阅读时间需要 6 分钟。

Android 录音中的那些坑- https://blog.csdn.net/lv_ws/article/details/52859794

> 扬声器、有线耳机、蓝牙耳机对手机通话或听音乐的影响
Android 耳机插拔流程源码跟踪浅析-
 对于有线耳机,监听Intent.ACTION_HEADSET_PLUG系统广播,对于蓝牙耳机,监听BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED系统广播
private BroadcastReceiver headsetPlugReceiver = new BroadcastReceiver() {  
        @Override  
        public void onReceive(Context context, Intent intent) {  
              
            String action = intent.getAction();  
            if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {  
                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();  
                if(BluetoothProfile.STATE_DISCONNECTED == adapter.getProfileConnectionState(BluetoothProfile.HEADSET)) {  
                    //Bluetooth headset is now disconnected  
                    handleHeadsetDisconnected();  
                }  
            } else if ("android.intent.action.HEADSET_PLUG".equals(action)) {  
                if (intent.hasExtra("state")) {  
                    int state = intent.getIntExtra("state", 0);  
                if (state == 1) {  
                    Toast.makeText(context, "插入耳机", Toast.LENGTH_SHORT).show();  
                } else if(state == 0){  
                    Toast.makeText(context, "拔出耳机", Toast.LENGTH_SHORT).show();  
                }  
            }  
        }  
          
    }; 
 
  监听Android的系统广播AudioManager.ACTION_AUDIO_BECOMING_NOISY, 但是这个广播只是针对有线耳机,或者无线耳机的手机断开连接的事件,监听不到有线耳机和蓝牙耳机的接入,但对于我的需求来说足够了,监听这个广播就没有延迟了,UI可以立即响应
private BroadcastReceiver headsetPlugReceiver = new BroadcastReceiver() {  
        @Override  
        public void onReceive(Context context, Intent intent) {  
            String action = intent.getAction();  
            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {  
                handleHeadsetDisconnected();  
            }  
        }     
    }; 

> 电话/短信的状态及拦截

 电话中的RIL机制 AT指令集及基带BaseBand,BP?
Android应用--简、美音乐播放器添加电话监听-
android音乐播放器监听电话状态- http://blog.csdn.net/piaozhiye/article/details/6429402

 短信拦截分为2种方式,其一是广播,其二是内容观察者;

 实现挂断电话的功能,就必须通过AIDL才行,然后利用反射来使用其方法。
Android开发——短信电话拦截/接听电话- http://blog.csdn.net/seu_calvin/article/details/51924279
Android 短信拦截&来去电话拦截- https://my.oschina.net/ososchina/blog/501874
Android 电话和短信拦截- http://blog.csdn.net/jeden/article/details/46621531
Android 来电(包括铃声),短信拦截的实现方法- http://blog.csdn.net/lyjit/article/details/51863740
 

你可能感兴趣的文章
nmap 使用方法详细介绍
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>