This article describes the method of android programming to implement telephone recording. Share it for your reference. The details are as follows:
Add permissions to the manifest file:
<uses-permission android:name=".READ_PHONE_STATE"/> <!-- existSDCardCreate and delete files permissions --> <uses-permission android:name=".MOUNT_UNMOUNT_FILESYSTEMS"/> <!-- PastSDCardWrite data permissions --> <uses-permission android:name=".WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name=".RECORD_AUDIO"/> <!-- accessinternetPermissions --> <uses-permission android:name=""/> <uses-permission android:name=".RECEIVE_BOOT_COMPLETED"/>
The java code is as follows:
public class PhoneListenerService extends Service { @Override public void onCreate() { TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //The status of the monitored phone (new MyListener(), PhoneStateListener.LISTEN_CALL_STATE); } private final class MyListener extends PhoneStateListener { private String num; private MediaRecorder recorder; public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_RINGING: /* When the phone comes in */ num = incomingNumber; break; case TelephonyManager.CALL_STATE_OFFHOOK: /* When you answer the phone */ try { File file = new File((), num + "_" + () + ".3gp"); recorder = new MediaRecorder(); ();//Sound collection source (microphone) (OutputFormat.THREE_GPP);//Output format (AudioEncoder.AMR_NB);//Audio encoding method (());//Output direction (); (); } catch (Exception e) { (); } break; case TelephonyManager.CALL_STATE_IDLE: /* When there is no state */ if (recorder != null) { (); (); } break; } } } }
I hope this article will be helpful to everyone's Android programming design.