/**将发送的短信插入数据库**/
ContentValues values = new ContentValues();
//发送时间
values.put("date", System.currentTimeMillis());
//阅读状态 0未读,1已读
values.put("read", 0);
//1为收 2为发
values.put("type", 1);
//送达号码
values.put("address", num);
//送达内容
values.put("body", text);
//插入短信库
context.getContentResolver().insert(Uri.parse("content://sms"),values);
在系统短信数据库里插入一条短信如何像新收到短信一样的有推送呢?貌似新短信是会发送一条广播的?模拟器重启后会提示有未读短信,我需要不重启就能提示,改如何实现呢?
private final String SMS_URI_CONVERSATION = "content://mms-sms/conversations/";
i.setData(Uri.parse(SMS_URI_CONVERSATION + thread_id));
最重要就是那个URI,thread_id就是短信里的thread_id
private void notification() {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification();
// 设置显示在手机最上边的状态栏的图标
n.icon = R.drawable.stat_notify_sms;
// 当当前的notification被放到状态栏上的时候,提示内容
n.tickerText = num + ":" + text;
n.flags = Notification.FLAG_AUTO_CANCEL;
Intent i = new Intent();
//直接启动系统短信
i.setComponent(new ComponentName("com.android.mms",
"com.android.mms.ui.ConversationList"));
i.setAction(Intent.ACTION_VIEW);
PendingIntent p = PendingIntent.getActivity(context, 0, i,
PendingIntent.FLAG_ONE_SHOT);
n.setLatestEventInfo(context, num, text, p);
nm.notify(1, n);
}
自己写了个通知,不完美