创建自定义通知android

时间:2016-04-05 10:36:51

标签: android android-notifications

如何创建自定义默认通知?我正在使用远程视图来创建通知。但它不是所期望的。下面是图片。我想创建通知,底部有两个按钮(如大会议定义。 任何教程都会非常有用。

enter image description here

下面是我写的代码片段。

Intent snoozeIntent = new Intent(LockableActivity.INTENT_SNOOZE);
        PendingIntent pendingSnoozeIntent = PendingIntent.getBroadcast(context, 0, snoozeIntent, 0);

        Intent gotItIntent = new Intent(LockableActivity.INTENT_GOT_IT);
        PendingIntent pendingGotItIntent = PendingIntent.getBroadcast(context, 0, gotItIntent, 0);

        RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.view_notification);
        remoteView.setTextViewText(R.id.tv_title, entity.getClientName() + " appointment is late");
        remoteView.setTextColor(R.id.tv_title, context.getResources().getColor(android.R.color.black));
        remoteView.setOnClickPendingIntent(R.id.btn_snooze, pendingSnoozeIntent);
        remoteView.setOnClickPendingIntent(R.id.btn_got_it, pendingGotItIntent);

        NotificationManager mNotificationManager = (NotificationManager)
        context.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_notification)
                        .setContentTitle(entity.getClientName() + " appointment is late")
                        .setAutoCancel(true)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.notification_content)))
                        .setContent(remoteView);

但是我有我的xml。还有其他方法我可以在底部DD按钮。

1 个答案:

答案 0 :(得分:0)

您需要将远程视图设置为通知

中的bigContentView字段
Notification notification = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle(entity.getClientName() + " appointment is late")
        .setAutoCancel(true).build();
notification.bigContentView = remoteView;
mNotificationManager .notify(0,notification);