单击Android通知栏无效

时间:2015-08-10 11:51:33

标签: android

我为自己的应用创建了自定义通知。 代码如下,但问题是当我点击通知时没有任何反应。

RemoteViews remoteViews = new RemoteViews(getPackageName(),
            R.layout.notification_bar_collapsed);

Notification.Builder mBuilder = new Notification.Builder(
            this).setSmallIcon(R.mipmap.ic_launcher).setContent(
            remoteViews);

Intent resultIntent = new Intent(context,MainActivity.class);
Notification notification = mBuilder.build();
PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    this,
                    0,
                    resultIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(1, notification);

更新

当我更换代码时

mBuilder.setContentIntent(resultPendingIntent);

notification.contentView=remoteViews;
notification.contentIntent=resultPendingIntent;

它有效,但仍然想知道原因!

0 个答案:

没有答案