service-Monitor Phone calls

Source: Internet
Author: User

public class Monitorphone extends Activity {telephonymanager tmanager; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main);// Get Telephonemanager Object Tmanager = (Telephonymanager) getsystemservice (context.telephony_service);// Create a call status listener phonestatelistener listener = new Phonestatelistener () {@Overridepublic void oncallstatechanged (int state, String incomingnumber) {switch (state) {//no status case telephonymanager.call_state_idle:break;case telephonymanager.call_state_offhook:break;//the case TelephonyManager.CALL_STATE_RINGING:OutputStream OS = null when the call bell rings; Try{os = Openfileoutput ("Phonelist", Mode_append);} catch (FileNotFoundException e) {e.printstacktrace ();} PrintStream PS = new PrintStream (OS);p s.println (New Date () + "Incoming call:" + incomingnumber);p s.close (); break;default:break;}; Super.oncallstatechanged (state, incomingnumber);}};/ /Monitor phone call status change Tmanager.listen (Listener, phonestatelistener.listen_call_state);}}

Mainfest file

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Crazyit.monitorphone "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/><uses-permission android:name=" Android.permiss Ion.        Read_phone_state "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_launcher " Android:label= "@string/app_name" android:theme= "@style/apptheme" > <activity android:n                Ame= "Crazyit.monitorphone.MonitorPhone" android:label= "@string/app_name" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Androi D.intent.category.launcher "/> </intent-filter> </activity> </application></m Anifest>

Telephonymanager is a service class that manages cell phone communication status and telephone network information, and this class provides a listen (Phonestatelistener listener,int events) method to monitor call status

Run the above program, you can see a phonelist file in the Ddms's File Explorer panel data/data/crazyit.monitorphone/files directory, the file will be imported to the computer can see the phone call information

Because I am testing with a real machine, I need root permission to export the file under DDMS, otherwise I can't open the folder

To get permission to open a folder in DDMS:

>ADB Shell

$ su

# chmod 755/data

# chmod 755/data/data

# chmod 755/data/data/crazyit.monitorphone/

# chmod 755/data/data/crazyit.monitorphone/files

service-Monitor Phone calls

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.