android: how can I get alphabetic name of SMS sender?

1.8k Views Asked by At

I'm working on Android App which receives SMS and handles them. Everything works fine except one moment. I don't know how to translate a custom sender ID to alphabetic name. e.g. I get SMS from a bank and I see a number instead of bank name, but another applications display name of a bank.

Here is the my code

            Uri allSMSes = Uri.parse("content://sms");

            String[] strColumns = { TextBasedSmsColumns.ADDRESS,
                                "MAX(" + TextBasedSmsColumns.DATE + ") as " + TextBasedSmsColumns.DATE,
                                "COUNT(" + TextBasedSmsColumns.BODY + ") as number",
                                "SUM(" + TextBasedSmsColumns.READ + ") as " + TextBasedSmsColumns.READ};

            Cursor c = getContentResolver().query(allSMSes, strColumns, 
                                                  "1=1) group by (" + TextBasedSmsColumns.ADDRESS ,null, null);

I have tried to run it on Android 5.1 and 6.0

1

There are 1 best solutions below

6
On BEST ANSWER

I think what you want is the sender ID. This can be set by the sender, if he doesn't set it to alphabetic (name) you can't retrieve it. As far as I know.

Edit: I think what you need is the column Person or Creator.

https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns.html here you can see all columns that you can get.