Bahaa Odeh
Bahaa Odeh

Reputation: 583

android java.lang.NoClassDefFoundError: android.app.Notification$Builder

i add my app to google play , but i get some crashes on notification bulider , this is the crash message

java.lang.NoClassDefFoundError: android.app.Notification$Builder

and this my notification create code ,

    public void CreateNtf(String text)
{   

    Notification notificationView;
    PendingIntent pendingIntent = PendingIntent.getActivity( MainActivity.this,0,getIntent(),Intent.FLAG_ACTIVITY_NEW_TASK);
    if(Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT <= 15){

         notificationView = new Notification.Builder(context)
        .setContentTitle(getResources().getString(R.string.app_name))
        .setContentText(text)
        //.setTicker(getResources().getString(R.string.app_name) + " " + text)
        .setWhen(System.currentTimeMillis())
        .setContentIntent(pendingIntent)
        //.setDefaults(Notification.DEFAULT_SOUND)
        .setAutoCancel(false)
        .setSmallIcon(R.drawable.ic_launcher)
        .getNotification();
    }else{
             notificationView = new Notification.Builder(context)
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(text)
            //.setTicker(getResources().getString(R.string.app_name) + " " + text)
            .setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent)
            //.setDefaults(Notification.DEFAULT_SOUND)
            .setAutoCancel(false)
            .setSmallIcon(R.drawable.ic_launcher)
            .build();

    }
    notificationView.flags |= Notification.FLAG_NO_CLEAR;
    notificationView.flags |= Notification.FLAG_ONGOING_EVENT;
  notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  notificationManager.notify(1, notificationView);




}

So how can i fix this problem please ? i still get errors and crashes in google play

Upvotes: 3

Views: 1562

Answers (2)

user2534313
user2534313

Reputation:

It's because of the support package issue,Try this, it worked for me https://stackoverflow.com/a/16523845/2534313

Upvotes: 0

TN.
TN.

Reputation: 19830

Notification.Builder is not supported on API lower than 11. You can use NotificationCompat.Builder or create notification directly and use setLatestEventInfo.

Upvotes: 2

Related Questions