2014-09-01 92 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