简单的实例code,作为参考用(关键code粗体+效果图) ! Hope can help you !
参考Android4.1 源码:packages/apps/Phone/src/com/android/phone/NotificationMgr.java
[Code]
mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
:
Notification.Builder builder = new Notification.Builder(mContext);
builder.setSmallIcon(android.R.drawable.stat_notify_missed_call).setTicker(mContext.getString(R.string.notification_missedCallTicker, callName))
.setWhen(date)
.setContentTitle(mContext.getText(titleResId))
.setContentText(expandedText)
.setContentIntent(PendingIntent.getActivity(mContext, 0, callLogIntent, 0))
.setAutoCancel(true)
.setDeleteIntent(createClearMissedCallsIntent());
// Simple workaround for issue 6476275; refrain having actions when the given number seems
// not a real one but a non-number which was embedded by methods outside (like
// PhoneUtils#modifyForSpecialCnapCases()).
// TODO: consider removing equals() checks here, and modify callers of this method instead.
if (mNumberMissedCalls == 1
&& !TextUtils.isEmpty(number)
&& !TextUtils.equals(number, mContext.getString(R.string.private_num))
&& !TextUtils.equals(number, mContext.getString(R.string.unknown))){
if (DBG) log("Add actions with the number " + number);
builder.addAction(R.drawable.stat_sys_phone_call,
mContext.getString(R.string.notification_missedCall_call_back),
PhoneApp.getCallBackPendingIntent(mContext, number));
builder.addAction(R.drawable.ic_text_holo_dark,
mContext.getString(R.string.notification_missedCall_message),
PhoneApp.getSendSmsFromNotificationPendingIntent(mContext, number));
if (photoIcon != null) {
builder.setLargeIcon(photoIcon);
} else if (photo instanceof BitmapDrawable) {
builder.setLargeIcon(((BitmapDrawable) photo).getBitmap());
}
} else {
if (DBG) {
log("Suppress actions. number: " + number + ", missedCalls: " + mNumberMissedCalls);
}
}
Notification notification = builder.getNotification();
configureLedNotification(notification);
mNotificationManager.notify(MISSED_CALL_NOTIFICATION, notification);
:
[End]