通知setStyle在棒棒糖中不起作用

时间:2016-01-26 08:40:15

标签: android android-5.0-lollipop android-notifications

我被困在通知中。 当我在棒棒糖下和棒棒糖下运行代码时,它运行正常。

但是,如果我在棒棒糖中运行代码,setstyle()方法无效。 我也尝试过使用远程视图,但它也无法正常工作。

我尝试使用BigPicture,但它也没有用。 我错过了什么? 请帮忙。

    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(largeIcon)
            .setContentTitle(title)
            .setContentText(content)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setAutoCancel(true)
            .setVibrate(new long[]{1000, 1000, 1000})
            .setSound(defaultSoundUri)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

我尝试了很多设备,发现它发生在Android 5.0.2版本中。

1 个答案:

答案 0 :(得分:0)

我没有发现任何问题,除了setContentText()删除它并尝试以下内容:

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(largeIcon)
            .setContentTitle(title)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setAutoCancel(true)
            .setVibrate(new long[]{1000, 1000, 1000})
            .setSound(defaultSoundUri)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());