3

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

pavel
  • 33
  • 4
  • Guessing here, but I think you have to lookup the number in the contacts – Memme Jul 05 '16 at 06:00
  • 1
    No, this is not a number in the contacts. For example, a bank sends messages about operations with a card. My app displays a number ( this is not a phone number ), but other applications see a name of bank and this number is not included into the contacts. I want to know how I can get the name of organization if I know the number. – pavel Jul 05 '16 at 09:39

1 Answers1

1

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.

user6547359
  • 204
  • 1
  • 9
  • @pavel editet the answer, should be what you need I hope – user6547359 Jul 05 '16 at 13:51
  • I need to get alphabetic (name). Another application which is installed by default can see alphabetic (name) , but my returns a number which is read from the field address. So, a sender id is set but I don't know how to get it. Perhaps I have to read this alphabetic (name) in another field, but I have not found where. – pavel Jul 05 '16 at 13:51
  • I have checked all this Columns but all of them do not include this info. – pavel Jul 05 '16 at 13:53
  • I have found a bug in my app. The problem was in the function which formats phone numbers, I shouldn't call it for alphabetic names. – pavel Jul 05 '16 at 14:51
  • yep :-). Alphabetic names are stored in the field address. – pavel Jul 05 '16 at 14:54
  • You should add an answer and accept it for others looking for same thing – user6547359 Jul 05 '16 at 14:55