Answer the question
In order to leave comments, you need to log in
Why is my app giving more notifications than it should?
In my application, after loading the phone, the time is set in the calendar for calling a reminder
public class BootUpReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context , NotifyService.class);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 22);
calendar.set(Calendar.MINUTE, 23);
calendar.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60 * 1000, pendingIntent); //set repeating every 24 hours
}
}
public class NotifyService extends Service {
NotificationManager nm;
@Override
public void onCreate() {
super.onCreate();
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
sendNotif();
return super.onStartCommand(intent, flags, startId);
}
void sendNotif() {
Intent intent = new Intent(this, SplashActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle("UpgradeIM")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setContentText("Пора написать отчёт за день")
.setAutoCancel(true);
//add sound
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(uri);
//vibrate
long[] v = {500,1000};
mBuilder.setVibrate(v);
nm.notify(3, mBuilder.build());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Answer the question
In order to leave comments, you need to log in
Looks okay. Or maybe you, while testing, set several alarms? Try calling cancel() with your intent. Reinstalling the app should help too. As far as I know, there is no api for getting all alarms.
AlarmManager starting from Android 4 (or 3?) is generally very strange and unpredictable.
In my application, I sweated a lot so that it worked once at the right time.
Here 's a little example without repetition, in the setNotification method .
Here 's a little example with repetitions, in the setUpdateRepeat method .
From what I remember:
You can get a list of all alarms via adb using the command:adb shell dumpsys alarm
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question