Sorry for the inaccurate title, I don't know how to express the concept in english.
I want to listen and store a incoming sms sent by any no-digits id (e.g. "FACEBOOK" or "VODAFONE" etc.
When a normal composed phone number (as 555-010-101 and similar) send me a sms, I normally listen to it and store it in the phone db.
Well, it seems like I can't do the same for those special ids.
My receiver is like many others snippets found around the web:
@Override
public void onReceive(Context context, Intent intent) {
message = "";
contactName = "";
// Get SMS map from Intent
Bundle extras = intent.getExtras();
if ( extras != null ) {
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);
// Get ContentResolver object for pushing encrypted SMS to incoming folder
ContentResolver contentResolver = context.getContentResolver();
assert smsExtra != null;
for (Object aSmsExtra : smsExtra) {
sms = SmsMessage.createFromPdu((byte[]) aSmsExtra);
String body = sms.getMessageBody();
address = sms.getOriginatingAddress();
message = body;
Uri uriConversation = Uri.parse("content://mms-sms/conversations/");
final String[] projection = new String[]{"*"};
final String selection = address;
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
Cursor cursor = contentResolver.query(uri, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);
// THREAD _ ID CURSOR
Cursor thread_id_cursor = contentResolver.query(
uriConversation,
projection,
selection,
null,
null
);
if (thread_id_cursor.moveToFirst()) {
thread_id = thread_id_cursor.getString(thread_id_cursor.getColumnIndexOrThrow(THREAD_ID));
}
if (cursor.moveToFirst()) {
contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
}
if (contactName != null && contactName.equals("")) {
contactName = address;
}
entireMessageText.append(sms.getDisplayMessageBody());
}
// Put the sms to database
putSmsToDatabase(contentResolver, sms, entireMessageText.toString());
NotificationHandler handler = new NotificationHandler(context);
handler.build();
}
}
I think I'm missing something for the special ids. Any suggestion would be really appreciated, thanks in advance.