简体   繁体   中英

NotificationCompat.BigTextStyle cannot be resolved to a type

I've added android-support-v4.jar in Java Build Path as well as in libs folder. Also, there's no error shown on the line

import android.support.v4.app.NotificationCompat;

Though I'm getting error on the line

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(
        R.drawable.heart_connect).setContentTitle(Consts.NOTIFICATION).setStyle(
        new NotificationCompat.BigTextStyle().bigText(messageValue)).setContentText(messageValue);

as:

NotificationCompat.BigTextStyle cannot be resolved to a type.

I also tried cleaning the project but that did not help. And also to my wonder, I've another project in the workspace with same piece of code and it works perfectly fine. Both projects have same libraries added to them as well.

This tiny stuff is annoying me too much now. Couldn't even guess the reason of error. Do I also need to add the library some other way?

Answering this because I have faced the same issue so that others can find this easily. We just need to replace the NotificationCompat with Notification like as below

Notification.Builder builder = new Notification.Builder(context).setContentTitle(notificationMessage.getTitle())
                    .setContentText(notificationMessage.getVersionMsg())
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent)
                    .setStyle(new Notification.BigTextStyle().bigText(notificationMessage.getVersionMsg()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM