The method of realizing telephone recording by Android programming _android

Source: Internet
Author: User
Tags file permissions

This article is an example of Android programming to achieve the telephone recording method. Share to everyone for your reference. Specifically as follows:

To add permissions in the manifest file Androidmanifest.xml:

<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<!--Create and delete file permissions in SDcard-->
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!-- Write data permissions to SDcard-->
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.RECORD_AUDIO"/>
<!--access to Internet permissions-->
< Uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= " Android.permission.RECEIVE_BOOT_COMPLETED "/>

The Java code is as follows:

public class Phonelistenerservice extends Service {@Override public void onCreate () {Telephonymanager manager = (T
 Elephonymanager) Getsystemservice (Context.telephony_service);
Monitor the status of the phone Manager.listen (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_ri
  Nging: * * When the phone comes in num = Incomingnumber;
  Break Case Telephonymanager.call_state_offhook:/* When the call is received/*/try {File File = new file (environment.getexternalstoragedirect
   Ory (), num + "_" + system.currenttimemillis () + ". 3gp");
   Recorder = new Mediarecorder ();
   Recorder.setaudiosource (audiosource.mic);//Sound acquisition Source (microphone) Recorder.setoutputformat (OUTPUTFORMAT.THREE_GPP);//output format Recorder.setaudioencoder (AUDIOENCODER.AMR_NB);//audio encoding mode Recorder.setoutputfile (File.getabsolutepath ());Output direction recorder.prepare ();
  Recorder.start ();
  catch (Exception e) {e.printstacktrace ();
  } break;
   Case Telephonymanager.call_state_idle:/* without any state */if (recorder!= null) {recorder.stop ();
  Recorder.release ();
 } break;

 }
 }
}
}

I hope this article will help you with your Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.