I want to find a way specific SMS that contains a specific word and answer back automatically.
I have found a way to answer the SMS but I still can't work on finding the SMS...
Its true that its not documented but people have been using this for years and if an update was to change the way we access the SMS database it would affect hundreds of users applications. So I doubt any time soon they would change this.
Anyway, start by creating a cursor object to the SMS database and just run a query with no conditions in the where clause. Then just run through the database pulling out the values you need. Someone was also nice enough to post the different column names in the database. Here they are: How many database columns associated with a SMS in android?
Below is a code snippet to get the SMS's from the database.
Cursor messages;
Columns message = ColumnsFactory.messages(); //points to structutre
messages = getContentResolver().query(Uri.parse("content://sms/"),
null, null, null, null);
while (messages.moveToNext()) {
//do stuff here.
Have you tried Google App Inventor? It has an example of this very type of app.
App inventor example website
In your broadcast receiver for incoming SMS, check the SMS body. If the SMS body contains that particular word then send a reply to that number. In the same way you can also check for incoming numbers.
Example to check for particular number:
if (smsBody.contentEquals("word to match")) {
// create reply
}
There is an undocumented content provider for SMS: "content://sms/inbox" . But this is not official and can change. There is no proper way of sms access.
Related
I am working on SMS Module.
I need to give searching contact via name, number and SMS via body?
I am able to search SMS body with CursorLoader via
content://mms-sms/search
Contacts separately via
ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI
So is there any separate URI search these two things which i am not aware of or Merge these two under one list With using CursorLoader.
Appreciate any lead.
or is there some way to improve sms search and customize it.
So is there any separate URI search these two things which i am not aware of or Merge these two under one list
No.
Also, bear in mind that not every SMS will be to or from a user's contact.
I'm building an App which relies heavily on the user's contacts.
I've created an Account and create RawContacts on behalf of this account when needed.
And I use SyncAdapter and things are great.
But I'm still missing some parts of this puzzle:
I'm trying to implement a behavior similar to WhatsApp. Such that-
When a change happens in the name or phone of any contact - it would be sent to the server for evaluation.
Whether this contact was already in "my" RawContacts, whether he was just created now by the user.
I know there's the ContentObserver but tracking ContactsContract.Contacts.CONTENT_URI seems like the wrong thing to do because it doesn't give the specific change, plus it gets raised to many times, and from to many events that don't interest me.
I know that WhatsApp are using SyncAdapter but I think they might be doing something more.
Any idea would be much appreciated.
ContentObserver tracking ContactsContract.Contacts.CONTENT_URI is indeed the way to go.
When you get onChange() you query the raw_contacts table with following condition:
String where = "(rawcontacts.dirty = true or rawcontacts.deleted = 1) and rawcontacts.account_type = <your_custom_type>"
The result will give you contacts added, updated or deleted.
If you are interested in knowing more details - the reason why you need to subscribe to ContactsContract.Contacts.CONTENT_URI is that the contacts provider currently does not notify which contacts were modified in onChange(). This is because of the applyBatch() transactions where multiple contacts may change. May be in future there will be a way to subscribe to a subset - but currently there is none.
Using the Messaging API in Android, is it possible to query the number of messages sent during a particular period - say 1 month?
I am not sure if using a BroadcastReceiver for the android.provider.Telephony.SMS_SENT event would be supported from Android 4.4 and up. I think this is the best approach as the first method will not be able to count if the user deletes some messages.
Can anyone give a better solution or if the first one I mentioned is possible?
Access the content provider
There is a content provider for accessing SMS messages, but it's not documented in the public SDK. If you use ContentResolver.query() with a Uri of content://sms you should be able to access these messages.
You can find more information on this Google Groups thread or previous questions on stackoverflow.
I'm in a very big trouble in building a simple custom SMS/MMS content provider wrapper class as long as it doesn't exist an official one for the android platform.
Obviously, to get data, i query on the "content://sms" and "content://mms" content provider using a cursor.
I found it fairly simple with SMS, because the columns names are quite intelligible and contains all data that a typical programmer needs in his application ("person" to get the sms sender/receiver contact id, "address" to get the sender/receiver phone number, "type" to get if the sms is an inbox, outbox, draft, sended sms etc...)
Unfortunately with MMS i've found a lot of trouble. The columns has unintelligible names (ex. "d_tm", "ct_cls", "retr_st", "d_rpt" etc.) and basic informations that i need, such as contact id, phone number, the type of the mms etc... seems to miss.
How can i get this information over the MMS?
I searched over all the 32 columns of the content provider but i didn't found what i need.
Thanks in advance!
P.S.
I know that google advise to avoid this kind of "low-level" operation over content providers that doesn't have a series of official class to access them, but i imagine that software house that operates in sms/mms management such as HandCent or Go Dev team, have built their own content provider using the same approach i'm using too.
Am i right or it exists unofficial libraries to manage SMS/MMS?
Thanks!
I googled a little bit more and finally i found that the correct way to get information like contact_id, phone number, type etc. about MMSs, is to open the content provider to the following
URI: "content://mms/{MmsId}/addr"
({MmsId} is the MMS "_id" column value).
Here i found all information i need.
Hope it helps!!!
I'm new to android programming. just to improve my skills, i started with some project in my mind.
when app starts, it will show a button. on click of it, it will allow me to select a contact from the address book. then i want to retrieve all the sms sent to that contact (if they are stored in sms outbox). Is it possible. Can some one guide me. If there is some tutorial on these topics, can you let me know the URL or source code?
Thanks in Advance.
First, it is not possible. There are many SMS clients for Android, many of whom do not expose an "sms outbox".
Second, even if you limit yourself to the SMS application that ships with "Google Experience" phones, the "sms outbox" is not part of the SDK.
If you wish to create an application that sends SMS messages, there is the SmsManager class you can use.
As folks mentioned, the sms outbox is undocument. If you want to access it, you sholud have some skills first.
trace android source code
learn how to use content provider (learn how to create a content provider is better)
what's the authority
know does the URI matched
how to manipulate the Cursor
write some sample code to test
You can find the SMS/MMS content provider here:
https://android.googlesource.com/platform/packages/providers/TelephonyProvider