我在服务中创建通知并在状态栏中显示通知时遇到问题...
这是我在活动中创建通知的方式:
int NOTIFY_ID=100;
Intent notificationIntent = new Intent(this, Grafik.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.notification)
.setContentTitle("Message")
.setContentText("Hello world");
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, mBuilder.build());
但是,当我将此代码放入我的服务中时,它会崩溃,我认为问题就在这里
Intent notificationIntent = new Intent(this, Grafik.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
在这里
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
但我不知道为什么......