3

バックグラウンド サービスで通知を送信する小さなアプリを開発しています。ユーザーが通知をクリックすると、適切なアクティビティを起動する必要があります。通知用のコードをここに投稿しています。私の問題は、通知がステータス バーに表示されることですが、クリックしてもアクティビティが開始されません。誰かが私が間違っている場所を提案できますか? 助けてください。

NotificationManager notificationManager = (NotificationManager) 
        getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
        "A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotificationService.this,
        com.jeris.android.MetroActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent
        .getService(NotificationService.this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(NotificationService.this, "Bullion",
        "Rates for "+ parsedDate+"has not been updated. Go to app to check rates",
        pendingIntent);
notificationManager.notify(11, notification);
4

1 に答える 1

5

交換 PendingIntent.getService(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

PendingIntent.getActivity(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

getServiceがgetActivityに置き換えられていることに注意してください。

于 2012-06-18T11:03:46.273 に答える