解读Notification在未接来电中的使用

来源:互联网 发布:centos libgcc s.so 编辑:程序博客网 时间:2024/05/18 21:08

先看看Phone中的源码:

// make the notification

        Notification note = new Notification(
                R.drawable.pic_icon_missed_call, 
                mContext.getString(R.string.notification_missedCallTicker, callName), 
                date
                );
        note.setLatestEventInfo(mContext, mContext.getText(titleResId), expandedText,
                PendingIntent.getActivity(mContext, 0, callLogIntent, 0));
        note.flags |= Notification.FLAG_AUTO_CANCEL;
        note.deleteIntent = createClearMissedCallsIntent();
        configureLedNotification(note);

        mNotificationManager.notify(MISSED_CALL_NOTIFICATION, note);


首先定义Notification 对象,三个参数:

R.drawable.pic_icon_missed_call:未接来电时状态栏显示icon,

mContext.getString(R.string.notification_missedCallTicker, callName):未接来电时状态栏显示的内容,比如:来自XXX的未接电话,callName就是XXX

date:系统当前时间

其次setLatestEventInfo方法,

mContext.getText(titleResId):状态栏下拉列表表示内容的title部分

expandedText:状态栏下拉列表表示内容的内容部分

PendingIntent.getActivity(mContext, 0, callLogIntent, 0)该语句的作用是定义了一个不是当即显示的activity,只有当用户拉下notify显示列表,并且单击对应的项的时候,才会触发系统跳转到该activity。也就是说在这里设置跳转到最近联系人的intent.

deleteIntent:清除未接来电的一个属性。

最后发出通知。

 

原创粉丝点击