2014-09-01 93 views
0

我创建收件箱文件夹内的短信如下:显示通知

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应用程序的意图来提出通知)?

+0

其中是通知代码.. ?? – SilentKiller 2014-09-01 13:02:42

+0

我目前还没有任何东西,因为我不知道如何做到这一点。关于使用SMS应用程序的内部通知权限? – NumberFour 2014-09-01 13:06:09

+0

,因为您在收件箱中创建短信,所以您也需要通知代码 – SilentKiller 2014-09-01 13:09:44

回答

1

建立通知是通过使用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

+0

谢谢,这有助于。它是否也播放声音?为了方便起见,我需要尽可能接近实际的短信通知。 – NumberFour 2014-09-01 13:16:01

+0

@NumberFour看看[第二个答案](http://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound)。还有什么我可以帮你的吗? – 2014-09-01 13:18:04

+1

太好了,那就是我需要的。谢谢! – NumberFour 2014-09-01 13:19:25