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
Notification.Builder is not supported on API lower than 11. You can use NotificationCompat.Builder or create notification directly and use setLatestEventInfo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With