Notification-setContent:已经过时了

时间:2016-11-24 10:36:59

标签: android

enter image description here setContent:已经过时了

setCustomContentView:API 24↑ 还有其他方法吗? enter image description here

1 个答案:

答案 0 :(得分:0)

我就是这样做的,只需使用NotificationCompat.Builder。

 // create RemoteViews
        final RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.remoteview_notification);

        remoteViews.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.future_studio_launcher);

        remoteViews.setTextViewText(R.id.remoteview_notification_headline, "Headline");
        remoteViews.setTextViewText(R.id.remoteview_notification_short_message, "Short Message");

        remoteViews.setTextColor(R.id.remoteview_notification_headline, getResources().getColor(android.R.color.black));
        remoteViews.setTextColor(R.id.remoteview_notification_short_message, getResources().getColor(android.R.color.black));

// build notification
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(UsageExampleTargetsAndRemoteViews.this)
                .setSmallIcon(R.mipmap.future_studio_launcher)
                .setContentTitle("Content Title")
                .setContentText("Content Text")
                .setContent(remoteViews)
                .setPriority(NotificationCompat.PRIORITY_MIN);

        final Notification notification = mBuilder.build();

// set big content view for newer androids
        if (android.os.Build.VERSION.SDK_INT >= 16) {
            notification.bigContentView = remoteViews;
        }

        NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, notification);