通知がいつクリアされるかを検出しようとしています。私の質問は、私がやろうとしていることを概説するこの回答を直接参照しています。これが私がアクションを実装する方法です:
// usual Notification initialization here
notification.deleteIntent = PendingIntent.getService(context, 0, new Intent(context, CleanUpIntent.class), 0);
notificationManager.notify(123, notification)
これは CleanUpIntent クラスです。
class CleanUpIntent extends IntentService {
public CleanUpIntent() {
super("CleanUpIntent");
}
@Override
protected void onHandleIntent(Intent arg0) {
// clean up code
}
}
その後、通常のように通知を起動するだけですが、テストしてみると ([すべての通知をクリア] を押します)、何も起こりません。IntentService の開始時に LogCat に何かを出力するコード行を挿入しましたが、何も実行されませんでした。これは私が Notification.deleteIntent を使用する方法ですか?