在你没有空闲记录电话内容时,电话录音软件就显得十分的方便了。无论是来电还是去电,都可以在SD存储卡上留下录音记录,以备日后查询。也可以做为陈堂证供哦!!!!!
首先,启动一个自定义的Service。作用是让操作在后台一直运行,只要来电话了就录音。
第二点就是利用TelephonyManager类判断现在电话的状态,在来电的情况下启动录音;
第三点利用mediaRecorder类来录音。具体我就不说了,请查看文档,不难的;录音的内容我放在了sd卡的根目录下面,你也可以修改在别的地方;
目前只是个雏形,但可以使用了。我就在用啊!!
private class BeginRecord implements OnClickListener{ @Override public void onClick(View v) { Intent serviceIntent=new Intent(getApplicationContext(),CallRecordService.class); getApplicationContext().startService(serviceIntent); } } }
@Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Toast.makeText(getApplicationContext(), "录音服务已经启动!", Toast.LENGTH_LONG).show(); // TelephonyManager telephonymanager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonymanager.listen(new PhoneListener(getApplicationContext()), PhoneStateListener.LISTEN_CALL_STATE); }public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber); mediaRecorder = new MediaRecorder(); switch(state){ case TelephonyManager.CALL_STATE_OFFHOOK: iscall=true; try { recordCallComment(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); mediaRecorder.stop(); } Toast.makeText(c, "正在录音", Toast.LENGTH_SHORT).show(); break; case TelephonyManager.CALL_STATE_IDLE: //if(mediaRecorder!=null){ //mediaRecorder.stop(); //mediaRecorder=null; //} if(iscall){ mediaRecorder.stop(); iscall=false; } break; } }
public void recordCallComment() throws IOException{
System.out.println(mediaRecorder); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder .setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); mediaRecorder .setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); audioFile = File.createTempFile("record_", ".amr"); mediaRecorder.setOutputFile(audioFile.getAbsolutePath()); mediaRecorder.prepare(); mediaRecorder.start(); }