Android4.1:通知栏显示可点击的按钮-Notification.builder Sample

简单的实例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]



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值