Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android studio – Multiple daily repeating notifications at their specific time between in their intervals

Posted on November 11, 2022 By

Solution 1 :

intent.putExtra(“NAME”,id);
int id = Integer.valueOf(intent.getStringExtra(“NAME”));

don’t working, ignore them.

Problem :

For my app, I should send notifications to user.

For example:

user set 3 notifications
12:00
18:00
08:00

I want to send each notification everyday until i cancel them individually. Notifications should be sent, even if the app is closed.

Main:

registerAlarm(12, 0, 1);
registerAlarm(18, 0, 2);
registerAlarm(8, 0, 3);

Main Methods:

 private PendingIntent registerAlarm(int hour, int minute, int id){
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);

    Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
    intent.putExtra("NAME",id);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, id, intent,0);
    AlarmManager am = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);

    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    System.out.println("SELAMLAR OLSUN ID MAIN: " + id);
    return pendingIntent;
}

private void cancelAlarm(int RSQ) {

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RSQ, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

Alarm Reciever:

public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);


    Intent notificationIntent = new Intent("com.demo.FirebaseMessagingReceiveService");
    notificationIntent.setClass(context, Main2Activity.class);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    int id = Integer.valueOf(intent.getStringExtra("NAME"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);


    Notification.Builder builder = new Notification.Builder(context)
            .setSmallIcon(R.drawable.ic_android_black_24dp)
            .setContentTitle("ONLINE QUIZ APP")
            .setContentText("HEY TRY TO SOLVE TODAY")
            .setSound(alarmSound)
            .setAutoCancel(true)
            .setWhen(when)
            .setContentIntent(pendingIntent)
            .setVibrate(new long[] {1000, 1000, 1000, 1000, 1000});

    context.startService(notificationIntent);
    notificationManager.notify(id, builder.build());



}

}

READ  [FIXED] java - how to keep randomUUID static
Powered by Inline Related Posts
Android Tags:android-notifications, android-studio, notifications, push-notification

Post navigation

Previous Post: [FIXED] android – Can you get the tag of a date picker
Next Post: [FIXED] Android Recyclerview add item and notifyiteminserted causes blink recycled view before draw the correct

Related Posts

[FIXED] java – Is there a way to turn on and off the flashlight of front camera? Android
[FIXED] kotlin – Android drawLine under view Android
[FIXED] Shut down android device using Flutter application Programmatically Android
[FIXED] android – Apple Sign In “invalid_client”, signing JWT for authentication using PHP and openSSL Android
[FIXED] java – Android 7.1 and lower double notifications showing Android
[FIXED] flutter – Cannot get list of data from cloud firestore Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme