私はアプリを開発しようとしていますが、問題に直面しました... 私のアプリでは、時と分などいくつかのデータを含むデータベースがあり、通知を作成したい時間列の場合。 SQLiteで通知を作成
は、私はこれらのコードで通知作成:public void scheduleNotification(Notification notification, int hour, int minute) {
Intent notificationIntent = new Intent(getContext().getApplicationContext(), TaskReceiver.class);
notificationIntent.putExtra(TaskReceiver.NOTIFICATION_ID, 0);
notificationIntent.putExtra(TaskReceiver.NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext().getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
private Notification getNotification(String content) {
Notification.Builder builder = new Notification.Builder(getContext());
builder.setContentTitle("Text Title");
builder.setContentText("Some Text");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setAutoCancel(true);
builder.setVibrate(new long[]{1000, 1000, 1000});
Intent intent = new Intent(getContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 1, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
builder.setContentIntent(pendingIntent);
return builder.build();
}
をなどの活動でそれを呼び出す:
Cursor c = dbManager.fetch();
if(c != null){
while (c.moveToNext()){
int hour = c.getInt(c.getColumnIndex(DatabaseHelper.CLOCK_HOUR));
int minute = c.getInt(c.getColumnIndex(DatabaseHelper.CLOCK_MINUTE));
scheduleNotification(getNotification("Test"), hour, minute);
}
}else {
Toast.makeText(getContext(), "Cursor is empty", Toast.LENGTH_SHORT).show();
}
しかし、それは誰も私を助けることができる、機能していませんか?
は、この方法を試してみてくださいhttps://stackoverflow.com/questions/44204387/alarmmanager-setinexactrepeating-setwindow-setrepeating-methods-do-not-fire-al/44205413#44205413 –
@AniruddhPariharデータベースからデータを読み込み、通知用に設定すると通知が表示されないので、私にとってはうまくいきません。なぜか分からない。 – rexo
「働いていない」とはどういう意味ですか?エラーメッセージが表示されますか、デバッグを試しましたか?はいの場合は、結果は何ですか? – PPartisan