Android-电话录音服务

Android-电话录音

TelephonyManager telManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

//通过电话管理监听通话状态(回调机制)

telManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

listener = new PhoneStateListener(){

         public void onCallStateChanged(int state,String incomingNumber){

                   Switch(state){

                            Case TelephonyManager.CALL_STATE_IDLE://空闲

                            CASE TelephonyManager.CALL_STATE_OFFHOOK:挂起电话

                            CASE TelepnhonyManager.CALL_STATE_RINGING:振铃

}

}

}

//录音

Recorder = new MediaRecorder();

recorder.setAudioSource(MediaRecorder.OutputFormat.THREE_GPP);//.3gp

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

recorder.setOutputFile(“/mnt/sdcard/”+filename);

recorder.prepare();

recorder.start();

recoding = true;

<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>

android2.0(API 5)测试通过,2.2不可以.

 

通过Receiver机制(收到手机启动完成的广播)启动电话录音服务

XxxReceiver extends Receiver{

         Public void onReceive(){

                   Intent = new Intent(this,XxxxService.class);

                   startService(intent);

}

}

//配置使用权限

<uses-permission

android:name = “android.permission.RECEIVE_BOOT_COMPLETED”/>

<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name=”android.permission.INTERNET”/>

<uses-permission android:name=”android.permission.RECORD_AUDIO”/>

注:

         电话录音者应用程序需要停止卡塔莎录屏软件,否则电脑卡死。

上一篇:Docker改名啦?什么是 Moby Project


下一篇:《Java 7程序设计入门经典》一2.6 运算符