Error NotificationCompat2: java.lang.IllegalArgumentException

I am trying to use NotificationCompat2 from JakeWharton . When ordering NotificationCompat2 it says

Just change your import from android.support.v4.app.NotificationCompat to com.jakewharton.notificationcompat2.NotificationCompat2 and use the NotificatonCompat2.Builder Class.

I changed the import to com.jakewharton.notificationcompat2.NotificationCompat2 and using the following code

 Notification notification = new NotificationCompat2.Builder( MainActivity.this).setContentTitle("Basic Notification") .setContentText("Basic Notification, used earlier") .setSmallIcon(R.drawable.lock).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, notification); 

and the application crashed with the following error

 08-17 20:14:32.400: E/AndroidRuntime(289): FATAL EXCEPTION: main 08-17 20:14:32.400: E/AndroidRuntime(289): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xyz.notificationchk/com.xyz.notificationchk.MainActivity}: java.lang.IllegalArgumentException: contentIntent required: pkg=com.wissenways.notificationchk id=0 notification=Notification(vibrate=null,sound=null,defaults=0x0) 

My question

What am I missing or fuzzy, which leads to a crash of the application?

+2
android android-notifications
Aug 17 2018-12-12T00:
source share
1 answer

I don’t know what this error is, but this piece of code works

 private static final int UPDATE_PROGRESS = 123654789; private NotificationManager notifManager; private Context mContext; private NotificationCompat2.Builder mNotification; private String content = ""; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = MainActivity.this; notifManager = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); mNotification = new NotificationCompat2.Builder(mContext) .setSmallIcon(android.R.drawable.sym_def_app_icon) .setTicker("Launch download") .setContentTitle("Downloader") .setContentText(content) .setContentIntent(getPendingIntent()); notifManager.notify(UPDATE_PROGRESS, mNotification.build() ); } private PendingIntent getPendingIntent() { Intent i = new Intent(mContext, MainActivity.class); i.setFlags(FLAG_ACTIVITY_CLEAR_TOP); return PendingIntent.getActivity(mContext, 0, i, 0); } 
+1
Aug 23 2018-12-18T00:
source share



All Articles