4

我在服务内创建通知并将其显示在状态栏中时遇到问题...

这就是我在活动中创建通知的方式:

    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)

但我不知道为什么...

4

0 回答 0