-2

I'm just done my lock screen application in Android. Now I want to improve it a bit with a notification on the lock screen when a sms received.

I got the content of the sms but I want to get the contact info of the sender. Anybody can help me to do that? Thanks in advance.

nchv
  • 61
  • 3
  • 11
  • @Aʟᴀɢᴀʀᴏs what I want to do like this [link](http://cdn.redmondpie.com/wp-content/uploads/2014/07/lock-screen-notifications.png) – nchv Aug 14 '15 at 01:28

1 Answers1

1

Start by getting the PDUs (Program Data Unit). From this, extract the information you desire. Search google for code examples to extract and read the data:

final Object[] pdusObj = (Object[]) bundle.get("pdus");
String who = new String();
String what = new String();
for (int i = 0; i < pdusObj.length; i++) {
                SmsMessage received = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                who = received.getDisplayOriginatingAddress();
                what = received.getDisplayMessageBody();
                Toast toast = Toast.makeText(contexto, "Who: " + who + "\n, What: " + what, Toast.LENGTH_LONG);
                toast.show();
            }
Bonatti
  • 2,778
  • 5
  • 23
  • 42
  • how can I get name and the avatar of the sender? – nchv Aug 14 '15 at 01:25
  • You get the originating phone number (the `who` in my code, then search the phone records for a contact with that number + the image the contact has (the avatar). [This may help you get started](http://stackoverflow.com/questions/3044545/get-contact-info-from-android-contact-picker) – Bonatti Aug 14 '15 at 11:11