0

通知を作成する方法があります。numberユーザーがステータス通知をクリックするとすぐに通知をクリアしたい。

public void createNotification(){

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification=null;
        notification = new Notification(R.drawable.ic_launcher, "You have a new message", System.currentTimeMillis());

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.number = **count**++;
        Intent intent = new Intent();
            intent.setClass(TabInterfaceActivity.this, TabInterfaceActivity.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.contentIntent = activity;
        notification.setLatestEventInfo(this, " New Message", message, notification.contentIntent);
}
4

1 に答える 1

0

通知番号をクリアしたい」とは、通知自体を表示したままにしておきたいが、カウンターを更新/削除したい場合は、このシナリオを処理するコードを指すように通知PendingIntentを設定する必要があります。あなた、そしてそれが完了すると、それはあなたのターゲットにリダイレクトしますTabInterfaceActivity(またはあなたはそれをより柔軟にし、PendingIntentのバンドルでターゲットを渡すことができます)。

于 2012-09-10T15:39:11.043 に答える