Android uses content viewer to implement SMS eavesdropping

Source: Internet
Author: User

"The principle of Android content observer" introduces some basic principles of the content observer, and does a simple combat, this article then further to do a small project combat

 PackageCom.wuyudong.smslistener;ImportJava.io.File;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;Importandroid.app.Activity;ImportAndroid.database.ContentObserver;ImportAndroid.database.Cursor;ImportAndroid.view.Menu; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Uri URI= Uri.parse ("Content://sms"); Getcontentresolver (). Registercontentobserver (URI,true,                NewMyobserver (NewHandler ())); }    Private classMyobserverextendsContentobserver { Publicmyobserver (Handler Handler) {Super(handler); } @Override Public voidOnChange (BooleanSelfchange) {System.out.println ("The SMS database has changed. "); Uri URI= Uri.parse ("Content://sms"); Cursor Cursor=getcontentresolver (). Query (URI,NewString[] {"Body", "address", "date", "type"},NULL,                    NULL, "_id desc");            Cursor.movetofirst (); String Body= cursor.getstring (0); String Address= cursor.getstring (1); String Date= Cursor.getstring (2); String type= Cursor.getstring (3); Try{ file file = new File (Getfilesdir (), "XXX.ABC"); FileOutputStream Fos=NewFileOutputStream (file,true); Fos.write (("Content:" + body + "--address" + adress + "--time:" +Date+ "--type" + type + "\ n"). GetBytes ());            Fos.close (); } Catch(Exception e) {e.printstacktrace (); }            Super. OnChange (Selfchange); }    }}

Add Permission: Android.permission.READ_SMS

After running the code, as long as the text message changes, will prompt, and the content of the text will be automatically saved in the Xxx.abc file

Android uses content viewer to implement SMS 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.