如何让我的通知执行操作onclick?

时间:2016-12-31 17:57:24

标签: android

默认的通知点击行为是为活动提供午餐,但我想显示祝酒或改为调用方法。我怎么做?

//**cleareble notification**//
NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification noti = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentIntent(
                    PendingIntent.getActivity(this, 0, getIntent(),
                            PendingIntent.FLAG_UPDATE_CURRENT))
            .setContentTitle("HELLO world")
            .setContentText("PLEASE CHECK WE HAVE UPDATED NEWS")
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(R.drawable.ic_launcher)
            .setTicker("ticker message")
            .setWhen(System.currentTimeMillis()).build();
    //noti.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(0, noti);

1 个答案:

答案 0 :(得分:1)

请查看Android开发者网站Building a Notification

中的此链接

基本上你创建一个PendingIntent并使用Notification.Builder的setContentIntent方法。

查看定义通知的操作部分和设置通知的点击行为