Zhao Yazhi _android SMS eavesdropping and Android SMS source code Analysis

Source: Internet
Author: User
Tags string tags

System code: Https://github.com/android

SMS Presence Location

Locate the Android system database: Data-data-com.android.providers.telephony-databases-mmssms.db



SMS Database Analysis


Export the Mmssms.db table and view it through Sqliteexpert, as

SMS Table: SMS Table


Table Structure Analysis:

Address: SMS Sender phone number

Person: Contact Number, if there is a contact in the phone book, displays the number, and no contact displays null.

READ: Reading status, 0 unread, 1 read

Body: SMS Content


Thread Table: Threads table


Datal: Date

Message_count: Number of lines sent by SMS

Snippet: Last SMS Content

READ: SMS Read status

Android SMS source code analysis in the SMS code of the Android system, Androidmenifest.xml defines an interface that provides an external query

Defines the urimatch operation for SMS-related URIs, such as read, unread, drafts, Inbox, Outbox


Steps
    • Add access rights in Androidmenifest.xml
    • Get Content Parser
    • Registered Observer
      • Uri
      • Observers
        • Handler
          • Listen when the news comes.
          • Find data from a database and show it
        • Constructors
        • When the database changes
Main code Androidmenifest.xml
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.android_readsms "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses -SDK android:minsdkversion= "8" android:targetsdkversion= "+"/> <!--SMS Read permissions--<uses-perm Ission android:name= "Android.permission.READ_SMS"/> <uses-permission android:name= "Android.permission.WRITE _sms "/> <instrumentation android:targetpackage=" com.example.android_readsms "Android:name="        Android.test.InstrumentationTestRunner "></instrumentation> <application android:allowbackup=" true " android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" > <activity android:name= "com.example.android_readsms.                Mainactivity "android:label=" @string/app_name "> <intent-filter><action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> </activity> <uses-library android:name=" android.t Est.runner "/> </application></manifest>


Mainactivity.java
Package Com.example.android_readconcats;import Java.util.list;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.support.v4.app.fragmentactivity;import Android.support.v4.app.fragmentmanager;import Android.support.v4.app.fragmenttransaction;import Android.widget.radiobutton;import Android.widget.radiogroup;import Android.widget.radiogroup.oncheckedchangelistener;import com.example.android_ Readphone.fragment.collectionfragment;import Com.example.android_readphone.fragment.concactsfragment;import Com.example.android_readphone.fragment.groupfragment;public class Mainactivity extends Fragmentactivity Implementsoncheckedchangelistener {private Radiogroup rg;private fragmentmanager fragmentmanager;//stored glyphs private String tags[] = {"Collection", "Contacts", "group"}, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_main);//Get Fragmentmanager Object Fragmentmanager = GetsupportfragmentmanageR (); rg = (Radiogroup) Findviewbyid (r.id.radiogroup1); Rg.setoncheckedchangelistener (this); Initmain ();} /** * Initialize first interface */private void Initmain () {//Get Fragmenttransaction object fragmenttransaction transaction = Fragmentmanager.begintransaction ();//Add favorite Transaction.add (r.id.show_content, New Collectionfragment (), "collection ");//Submit Transaction.commit ();} /** * Replace panel */private void Replacemain (String tag) {//Get Fragmenttransaction object fragmenttransaction transaction = Fragmentma Nager.begintransaction (), if ("Contacts". Equals (tag)) {//Replace contact Transaction.replace (r.id.show_content, new Concactsfragment (), "Contacts");} else if ("group". Equals (tag)) {//Replace add Group Transaction.replace (r.id.show_content, New Groupfragment (), "Group");} else if ( "Collection". Equals (TAG) {//Replace add Group Transaction.replace (r.id.show_content, New Collectionfragment (), "Collection");} Submit Transaction.commit ();} /** * Replace panel */private void Replacemains (String tag) {Fragment Fragmenttag = Fragmentmanager.findfragmentbytag (tag); if (FRA Gmenttag = =NULL) {if ("Contacts". Equals (Tag)) {fragmentmanager.begintransaction (). Add (R.id.show_content, New Concactsfragment ( ), "Contacts"). commit ();} else if ("group". Equals (Tag)) {fragmentmanager.begintransaction (). Add (R.id.show_content, New Groupfragment (), "group "). commit ();} else if ("collection". Equals (Tag)) {fragmentmanager.begintransaction (). Add (R.id.show_content, new Collectionfragment (), "collection"). commit ();}} else {//To determine if you have actually added if (fragmenttag.isadded ()) {fragmentmanager.begintransaction (). Show (Fragmenttag). commit ();//Display}} Get all the fragments that have been added list<fragment> flist = fragmentmanager.getfragments ();//Traverse all fragments for (Fragment fragment:flist) {// The broken tag is whether to display the fragment if (!tag.equals (Fragment.gettag ())) {fragmentmanager.begintransaction (). Hide (fragment). commit ();// Hide}} @Overridepublic void OnCheckedChanged (radiogroup group, int checkid) {switch (checkid) {case r.id.rb_collection: Replacemain ("collection"); Break;case r.id.rb_contacts:replacemain ("Contacts"); Break;case R.id.tb_group: Replacemain ("GrouP "); break;default:break;}}} 

The run effect uses DDMS's emulator control to send text messages to the simulator:

The client displays as follows:

Knowledge points involved: ContentProvider content parser ContentProvider content Watcher Handler
System comes with SMS Source: http://download.csdn.net/detail/zhaoyazhi2129/7491105
SMS Backup
    1. Read the text in the system
    2. Write the text you read as an XML file (SMS Backup)
    3. Write the XML file uploaded to the server
    4. Download it from the server and parse the XML file out
    5. INSERT into a database of your own creation (SMS recovery)

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.