tiempo real pagina notificaciones lanzar con alerta java android time alarmmanager android-notifications

real - notificaciones push web java



¿Por qué aumentar la notificación de dosis al establecer la hora de la notificación? (0)

He usado el selector de tiempo para establecer el momento de la notificación por parte del usuario. He usado el administrador de alarmas y el creador de notificaciones.

He llamado al método setAlarm en clickListener de un botón para guardar datos. Entonces, cuando se llama a este método setAlarm, la notificación aumenta al mismo tiempo que aumenta en el momento en que el usuario ha establecido.

No quiero que se levante cuando guardo los datos.

¿Alguien puede decir por qué está sucediendo esto?

método setAlarm

@SuppressLint("NewApi") private void setAlarm(Calendar targetmCalen) { AlarmManager alarmMgr; PendingIntent alarmIntent; alarmMgr = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplicationContext(), NotificationReceiver.class); alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); Toast.makeText(getBaseContext(), "call alarmManager.setExact()", Toast.LENGTH_LONG).show(); intent.putExtra("title",eventTitle); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, targetmCalen.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent); ComponentName receiver = new ComponentName(getApplicationContext(),NotificationReceiver.class); PackageManager pm = getApplicationContext().getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }

NotificationReceiver

public class NotificationReceiver extends BroadcastReceiver { private static final int MY_NOTIFICATION_ID = 0; NotificationManager notificationManager; Notification myNotification; EventTableHelper db; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Time is set", Toast.LENGTH_LONG).show(); db = new EventTableHelper(context); List<EventData> testSavings = db.getAllEvents(); for (EventData ts : testSavings) { String log = "from date:" + ts.getFromDate() + " ,to date: " + ts.getToDate() + " ,location: " + ts.getLocation() + " ,title " + ts.getTitle(); Date date = new Date(); Date date1 = new Date(); Log.d("Result: ", log); SimpleDateFormat df = new SimpleDateFormat("E MMM dd HH:mm:ss zzzz yyyy"); SimpleDateFormat df2 = new SimpleDateFormat("HH:mm a"); try { date = df.parse(ts.getFromDate()); date1 = df.parse(ts.getToDate()); } catch (ParseException ex) { } String timeFrom = df2.format(date); String startTime = String.valueOf(timeFrom); String timeTo = df2.format(date1); String endTime = String.valueOf(timeTo); String location = ts.getLocation(); String title = ts.getTitle(); Intent myIntent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity( context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); if(location.equals("")) { String msg = "From : " + startTime + "/nTo : " + endTime; myNotification = new NotificationCompat.Builder(context) .setContentTitle("Event : " + title) .setContentText(msg) .setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent) .setAutoCancel(true) .setSmallIcon(R.drawable.eventicon) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setDefaults(Notification.DEFAULT_SOUND) .build(); } else { String msg = "From : " + startTime + "/nTo : " + endTime + "/nAt : " + location; myNotification = new NotificationCompat.Builder(context) .setContentTitle("Event : " + title) .setContentText(msg) .setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent) .setAutoCancel(true) .setSmallIcon(R.drawable.eventicon) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setDefaults(Notification.DEFAULT_SOUND) .build(); } Log.i("Notify", "Notification"); notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(MY_NOTIFICATION_ID, myNotification); } } }

EDITAR:

Calendar object Passed in setAlarm method c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND,0); c.set(Calendar.MILLISECOND,0); c.set(Calendar.DATE, day); c.set(Calendar.DAY_OF_WEEK,2); notification = c.getTime(); notificationTime = df.format(notification); Toast.makeText(getApplicationContext(),notificationTime,Toast.LENGTH_SHORT).show();

Gracias..