私は特定のタスクを実行する必要があることを示す月の25日ごとに通知を受け取るAndroidアプリ用の関数を作成したいと考えています。Android:特定の日付に通知メッセージをスケジュールする
私は、次のコード使用して通知を表示することができました。今、このシステムは唯一、私は私のアプリを開いているときに動作し、私はこれを表示することはできません
public class NotificationPublisher extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long[] pattern = {0, 300, 0};
PendingIntent pi = PendingIntent.getActivity(context,, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.small_logo_ico)
.setContentTitle(context.getResources().getString(R.string.notification_title))
.setContentText(context.getResources().getString(R.string.notification_content))
.setVibrate(pattern)
.setAutoCancel(true);
mBuilder.setContentIntent(pi);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(, mBuilder.build());
}
}
をアプリが閉じられたとき。 Android notification at specific date これを試した後(スケジュール部分)、受信者の登録を解除する際にエラーが発生するので、アプリを終了すると動作しないことに気付きました(登録を解除する)受信者がキャンセルされ、通知が表示されません。スケジュールのために使用さ
コード:
NotificationPublisher receiver = new NotificationPublisher();
this.receiver = receiver;
IntentFilter filter = new IntentFilter("ALARM_ACTION");
registerReceiver(receiver, filter);
Intent intent = new Intent("ALARM_ACTION");
intent.putExtra("param", "My scheduled action");
PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent, 0);
// I choose 15s after the launch of my application
alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+15000, operation) ;
私が欠けている、または私は特定の日付の通知をスケジュールするために間違った方法を使用しています何がありますか? (現在の通知は、将来15秒間スケジュールされるように設定されています。これはテストのためのものです。特定の日付にこれを表示する機能が用意されています)
http://stackoverflow.com/questions/31086226/show-a-notification-on-a-particular-date-and-time – HAXM