Reputation: 701
How can I access messages in android? is there a separate method which enables reading from inbox?
Upvotes: 1
Views: 763
Reputation: 25755
I guess you*re talking about the SMS-Inbox. In this case, you would use the SMSManager (Demo).
Attention: The SMS Manager from the "android.telephony*.gsm*.SmsManager" Package is deprecated. Use the SMS Manager from the "android.telephony.SmsManager"-Package.
Upvotes: 0
Reputation: 39558
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.
You can also try this:
public List<String> getSMS(){
List<String> sms = new ArrayList<String>();
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
String body = cur.getString(cur.getColumnIndexOrThrow("body"));
sms.add("Number: " + address + " .Message: " + body);
}
return sms;
}
Upvotes: 2