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