我有一个日期和时间,当前时间的毫秒生成通知

时间:2019-06-24 08:10:26

标签: android push-notification notifications

我有一个日期数组列表。根据该列表,我想在我的应用中设置余数并生成通知

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

0 个答案:

没有答案