我正在尝试使用JakeWharton 的 NotificationCompat2。NotificationCompat2 的文档说
只需将您的导入从 android.support.v4.app.NotificationCompat 更改为 com.jakewharton.notificationcompat2.NotificationCompat2 并使用 NotificatonCompat2.Builder 类。
我已将导入更改为com.jakewharton.notificationcompat2.NotificationCompat2
并使用以下代码
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);
并且应用程序因以下错误而崩溃
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)
我的问题
我遗漏了什么或编码错误导致应用程序崩溃?