У меня есть дата и время, а Текущее время миллис генерирует уведомления - PullRequest
0 голосов
/ 24 июня 2019

У меня есть список массивов дат. В соответствии с этим списком я хочу установить остаток в моем приложении и генерировать уведомление

for (int i = 0; i < mStrings.size(); i++) {
            //final long id = getIntent().getExtras().getLong(getString(R.string.row_id_long));
            cv = new ContentValues();
            cv.put(mDbHelper.TITLE, "title");
            cv.put(mDbHelper.DETAIL, "Content");
            cv.put(mDbHelper.TYPE, "Notify");
            cv.put(mDbHelper.TIME, "Not Set");
            Calendar calender = Calendar.getInstance();
//calender.setTimeInMillis(Long.parseLong(mStrings.get(i).toString()));  //here your time in miliseconds
            String date = "" + calender.get(Calendar.DAY_OF_MONTH) + ":" + calender.get(Calendar.MONTH) + ":" + calender.get(Calendar.YEAR);
            String time = "" + calender.get(Calendar.HOUR_OF_DAY) + ":" + calender.get(Calendar.MINUTE) + ":" + calender.get(Calendar.SECOND);
//     Log.e("Data======", date + "=======" + time);
            calender.set(Calendar.MONTH, calender.get(Calendar.MONTH));
            calender.set(Calendar.DAY_OF_MONTH, calender.get(Calendar.DAY_OF_MONTH));
            calender.set(Calendar.YEAR, calender.get(Calendar.YEAR));
            calender.set(Calendar.HOUR, calender.get(Calendar.HOUR_OF_DAY));
            calender.set(Calendar.MINUTE, calender.get(Calendar.MINUTE));
            calender.set(Calendar.SECOND, 00);
            SimpleDateFormat formatter = new SimpleDateFormat(getString(R.string.hour_minutes));
            String timeString = formatter.format(new Date(calender.getTimeInMillis()));
            SimpleDateFormat dateformatter = new SimpleDateFormat(getString(R.string.dateformate));
            String dateString = dateformatter.format(new Date(calender.getTimeInMillis()));
            AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            Intent intent = new Intent(this, NotificationManager2.class);
            intent.putExtra("title", "title");
            intent.putExtra("title", "title ");
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
            alarmMgr.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
            cv.put(mDbHelper.TIME, timeString);
            cv.put(mDbHelper.DATE, dateString);
            Log.e("Date and time===", "" + timeString + "======" + dateString);
            db.insert(mDbHelper.TABLE_NAME, null, cv);
}

Класс NotificationManager2 расширяет BroadcastReceiver

открытый класс AlarmReceiver расширяет BroadcastReceiver

...