我有一个通知,我想关闭按钮关闭。我使用SetAutoCancel但它不起作用。任何人都知道如何实现它?使用此按钮remoteViews.setOnClickPendingIntent(R.id.notificationbutton, pIntent);
代码
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.customnotification);
String strtitle = getString(R.string.customnotificationtitle);
Intent intent = new Intent(this, NotificationView.class);
intent.putExtra("text", strtext);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.notificationbutton, pIntent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.logosmall)
.setTicker(getString(R.string.customnotificationticker))
.setAutoCancel(true).setContentIntent(pIntent)
.setContent(remoteViews);
remoteViews.setImageViewResource(R.id.imagenotileft,
R.drawable.ic_launcher);
remoteViews.setTextViewText(R.id.title,
getString(R.string.customnotificationtitle));
remoteViews.setTextViewText(R.id.text,
getString(R.string.customnotificationtext));
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
答案 0 :(得分:3)
autoCancel仅在调用默认通知单击时才会起作用,如果您使用的按钮必须清除自己的通知
关于为什么在有builder.addAction时使用自定义按钮的主题?