33

Beginner Android dev here.

I'm trying to create an app that will read the SMS messages stored on the device and then give the user statistics about their habits (like who they message often, common words, etc).

But to my knowledge, there doesn't seem to be a way to do this. I've looked around on forums and the most anyone talks about is accessing the inbox where you can find messages the user hasn't read. How then can the default app and third-party (Handcent for example) display the same texts? They don't keep their own database because Handcent will display all texts upon fresh install.

tl;dr: How do I read SMS messages on an Android devices, specifically messages that have been read before.

eternalmatt
  • 3,524
  • 4
  • 25
  • 25
  • 1
    There is no documented and supported means of accessing the data you request. There are undocumented and unsupported means, such as the stuff linked to by Sebastian P. Google has explicitly indicated that doing this is a bad idea: http://android-developers.blogspot.com/2010/05/be-careful-with-content-providers.html – CommonsWare Jan 26 '11 at 21:20
  • 1
    I guess that explains why I had such trouble finding examples. Honestly, I really don't understand this practice. Why does Google create useful code like Content Providers and then make no commitment to keep that code or require that code to be used by hardware manufacturers? I think I'm really beginning to understand the "fragmentation" issue. – eternalmatt Jan 26 '11 at 21:51

3 Answers3

26

For a concrete example of accessing the SMS/MMS database, take a look at gTalkSMS.

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118
  • The gTalkSMS example appears to be what I've been searching for. The other tutorial was just about the inbox I believe. Thanks! – eternalmatt Jan 26 '11 at 21:34
  • 2
    To future onlookers, a highly helpful class in gTalkSMS is the [SmsManager](https://code.google.com/p/gtalksms/source/browse/src/com/googlecode/gtalksms/cmd/smsCmd/SmsManager.java) class. – eternalmatt Mar 12 '13 at 00:18
  • This answer does not match the suggested quality-levels here on SO. It has to be considered a "link only answer" which is discurraged. – arkascha Jun 10 '20 at 13:14
3

You are going to need to call the SmsManager class. You are probably going to need to use the STATUS_ON_ICC_READ constant and maybe put what you get there into your apps local db so that you can keep track of what you have already read vs the new stuff for your app to parse through. BUT bear in mind that you have to declare the use of the class in your manifest, so users will see that you have access to their SMS called out in the permissions dialogue they get when they install. Seeing SMS access is unusual and could put some users off. Good luck.

Here is the link that goes into depth on the Sms Manager

enb081
  • 3,831
  • 11
  • 43
  • 66
cigloo
  • 21
  • 2
  • 3
    But if the OP is writing an SMS app, then an SMS app requesting permission to read SMS should not be considered "unusual", right? Common sense dictates that if you want your SMS app to display your messages, it will need to be able to access and "read" them, right? – RǢF Jan 15 '15 at 13:02
-2

Do the following, download SQLLite Database Browser from here:

Locate your db. file in your phone.

Then, as soon you install the program go to: "Browse Data", you will see all the SMS there!!

You can actually export the data to an excel file or SQL.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Hocsan
  • 57
  • 8
    The absolute path to the sms database is: /data/data/com.android.providers/telephony/databases/mmssms.db This path can not be accessed unless the device is rooted and the application requests superuser permission. – Xarph Aug 05 '12 at 06:43
  • 1
    ^ Though it may be helpful for people looking into this non-programaticaly, so although it doesn't answer the question it adds to the context. – Enrico Dec 14 '16 at 18:59
  • Android Studio 2021.3 includes an SQLLite database browser. **Android 4.3 or older:** `/data/data/com.android.providers/telephony/database/mmssms.db`. **Android 4.4 or later:** `/data/data/com.android.providers.telephony/database/mmssms.db`. **Android 7.0 and above:** `/data/user_de/0/com.android.providers.telephony/databases/mmssms.db`. – WebViewer Dec 31 '22 at 20:22