0

I'm creating an SMS message inside Inbox folder as follows:

ContentValues values = new ContentValues();
values.put("address", sender);
values.put("date", System.currentTimeMillis());
values.put("read", 0); // Message not read
values.put("status", 0);
values.put("type", 1);
values.put("seen", 0);
values.put("body", body);

ContentResolver rslv = context.getContentResolver();        
rslv.insert(Uri.parse("content://sms"), values);

This works well, but doesn't fire the usual "SMS received" notification in the top bar and play the notfitication sound. How do I do write such notification code (which presumably calls some SMS application's Intent to raise the notification) ?

NumberFour
  • 3,551
  • 8
  • 48
  • 72

1 Answers1

0

Building a notification is done by using Notification.Builder class. A really simple example is this:

Notification noti = new Notification.Builder(mContext)
         .setContentTitle("New SMS from " + sender.toString())
         .setContentText(subject) 
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap) 
         .build();   

More information is available in the official tutorial for the same.

An SO User
  • 24,612
  • 35
  • 133
  • 221
  • Thanks, this helps. Does it also play the sound? I need to get as close to the actual SMS notification as possible for the convenience. – NumberFour Sep 01 '14 at 13:16
  • @NumberFour Have a look at the [second answer](http://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound). Anything else I can help you with? – An SO User Sep 01 '14 at 13:18
  • Ok, I have one more question :) Where do I get the `R.drawable.new_mail` and the common icons, is it the android support library? Or do I have to add my own one? – NumberFour Sep 01 '14 at 13:27
  • @NumberFour Add your own. :) It is simply `R.drawable` and not `android.R.drawable` so you can see that it is specific to the app and not in the standard library :) – An SO User Sep 01 '14 at 13:59