显示有关收到的短信的通知

时间:2014-09-01 13:00:18

标签: android sms android-notifications

我正在Inbox文件夹中创建一条短信,如下所示:

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);

这很有效,但不会触发顶部栏中通常的“短信收到”通知并播放不合适的声音。 我该怎么写这样的通知代码(可能会调用一些SMS应用程序的意图提出通知)?

1 个答案:

答案 0 :(得分:0)

使用Notification.Builder类完成通知。一个非常简单的例子就是:

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

official tutorial提供了相同的更多信息。

相关问题