telephonyManager的使用
来源:互联网 发布:怎么安装mac os x 编辑:程序博客网 时间:2024/06/06 10:55
在服务 中配制,telephonyManager的实例化用TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
public class PhoneService extends Service {@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stubreturn null;}@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);tm.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);}public class MyPhoneStateListener extends PhoneStateListener{private MediaRecorder recorder;@Overridepublic void onCallStateChanged(int state, String incomingNumber) {// TODO Auto-generated method stubsuper.onCallStateChanged(state, incomingNumber);switch (state) {case TelephonyManager.CALL_STATE_IDLE:System.out.println("空闲");if(recorder != null) { recorder.stop(); recorder.reset(); // You can reuse the object by going back to setAudioSource() step recorder.release(); // Now the object cannot be reused}break;case TelephonyManager.CALL_STATE_OFFHOOK:System.out.println("监听");recorder.start(); // Recording is now startedbreak;case TelephonyManager.CALL_STATE_RINGING:System.out.println("铃声");recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile("mnt/sdcard/a.3gp"); try {recorder.prepare();} catch (IllegalStateException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}break;}}}}
阅读全文
0 0
- TelephonyManager.listen的使用
- telephonyManager的使用
- TelephonyManager类的使用案例
- Android TelephonyManager类的使用
- SubscriptionManager,SubscriptionInfo,TelephonyManager的使用
- TelephonyManager使用
- Android之TelephonyManager类的使用案例
- Service之TelephonyManager使用
- Android使用TelephonyManager
- [android基础知识] 之四:TelephonyManager service的使用实例
- 使用TelephonyManager监听通话事件的内存泄露
- TelephonyManager的完全使用方法
- Android的TelephonyManager用法
- Android TelephonyManager 的来源
- TelephonyManager
- TelephonyManager
- TelephonyManager
- TelephonyManager
- Python入门——while
- VS2013安装部署项目为安装包超详细
- 03-元素定位-基本
- 用于多(情况多)路选择的:switch语句(无break跳出)
- 如何在PostgreSQL中实现增量备份
- telephonyManager的使用
- 字符串搜索函数应用
- C语言与指针学习笔记
- 剑指offer每日一刷-2017年11月12日
- MySQL install
- 朴素贝叶斯的python代码实现
- 王学岗代理模式
- Android 简单断点续传|下载到本地
- HDOJ 1393 Weird Clock