Is there a device-agnostic way to handle simple recurring push notifications in Android?












1















Push notifications are still working great on all my devices running anything under 8.0, but anything 8.0+ is a nightmare.



Let's say I want a simple daily notification to pop up. It goes off once a day at a certain time, even if the application is closed. Exact timing isn't relevant:



    AlarmManager am =(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, alarmnotify.class);
PendingIntent pi = PendingIntent.getBroadcast(context, ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_DAY, pi);


On many devices supporting Doze this doesn't work and I have to use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() and refresh the alarm when it fires (annoying). But many more devices, this doesn't work either.



If the device is stock Android I can request an "ignore battery optimization privilege", but this isn't working for almost any of my testing devices because of some silly OEM battery manager that runs on top of the stock battery manager. Even Samsung has one of these now. And plus, Google does not recommend this approach, and it can get your app de-listed if they feel you don't need it.



    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);


Some devices are working if I use AlarmManager.setAlarmClock(), but this is silly, my app is not an alarm clock, I just want to display a notification.



I considered moving to FCM, but it's ridiculous to build client-server infrastructure over a simple once-daily alarm. Plus, that brings in numerous other considerations. The simplest: what if the user is offline?



I'm noticing this a major issue even in enterprise grade applications with millions of downloads. I have the same applications installed on a 7.0 and 9.0 device. The 7.0 device gets notifications and the 9.0 does not. What gives?



Is there a universal approach to handling alarms post-8.0, much like the first snippet was universal to all devices prior to 8.0?










share|improve this question























  • I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

    – Ankit
    Nov 13 '18 at 5:39













  • @Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

    – AardvarkBlue
    Nov 13 '18 at 5:49











  • I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

    – Ankit
    Nov 13 '18 at 6:15











  • @Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

    – AardvarkBlue
    Nov 13 '18 at 6:40
















1















Push notifications are still working great on all my devices running anything under 8.0, but anything 8.0+ is a nightmare.



Let's say I want a simple daily notification to pop up. It goes off once a day at a certain time, even if the application is closed. Exact timing isn't relevant:



    AlarmManager am =(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, alarmnotify.class);
PendingIntent pi = PendingIntent.getBroadcast(context, ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_DAY, pi);


On many devices supporting Doze this doesn't work and I have to use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() and refresh the alarm when it fires (annoying). But many more devices, this doesn't work either.



If the device is stock Android I can request an "ignore battery optimization privilege", but this isn't working for almost any of my testing devices because of some silly OEM battery manager that runs on top of the stock battery manager. Even Samsung has one of these now. And plus, Google does not recommend this approach, and it can get your app de-listed if they feel you don't need it.



    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);


Some devices are working if I use AlarmManager.setAlarmClock(), but this is silly, my app is not an alarm clock, I just want to display a notification.



I considered moving to FCM, but it's ridiculous to build client-server infrastructure over a simple once-daily alarm. Plus, that brings in numerous other considerations. The simplest: what if the user is offline?



I'm noticing this a major issue even in enterprise grade applications with millions of downloads. I have the same applications installed on a 7.0 and 9.0 device. The 7.0 device gets notifications and the 9.0 does not. What gives?



Is there a universal approach to handling alarms post-8.0, much like the first snippet was universal to all devices prior to 8.0?










share|improve this question























  • I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

    – Ankit
    Nov 13 '18 at 5:39













  • @Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

    – AardvarkBlue
    Nov 13 '18 at 5:49











  • I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

    – Ankit
    Nov 13 '18 at 6:15











  • @Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

    – AardvarkBlue
    Nov 13 '18 at 6:40














1












1








1


2






Push notifications are still working great on all my devices running anything under 8.0, but anything 8.0+ is a nightmare.



Let's say I want a simple daily notification to pop up. It goes off once a day at a certain time, even if the application is closed. Exact timing isn't relevant:



    AlarmManager am =(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, alarmnotify.class);
PendingIntent pi = PendingIntent.getBroadcast(context, ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_DAY, pi);


On many devices supporting Doze this doesn't work and I have to use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() and refresh the alarm when it fires (annoying). But many more devices, this doesn't work either.



If the device is stock Android I can request an "ignore battery optimization privilege", but this isn't working for almost any of my testing devices because of some silly OEM battery manager that runs on top of the stock battery manager. Even Samsung has one of these now. And plus, Google does not recommend this approach, and it can get your app de-listed if they feel you don't need it.



    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);


Some devices are working if I use AlarmManager.setAlarmClock(), but this is silly, my app is not an alarm clock, I just want to display a notification.



I considered moving to FCM, but it's ridiculous to build client-server infrastructure over a simple once-daily alarm. Plus, that brings in numerous other considerations. The simplest: what if the user is offline?



I'm noticing this a major issue even in enterprise grade applications with millions of downloads. I have the same applications installed on a 7.0 and 9.0 device. The 7.0 device gets notifications and the 9.0 does not. What gives?



Is there a universal approach to handling alarms post-8.0, much like the first snippet was universal to all devices prior to 8.0?










share|improve this question














Push notifications are still working great on all my devices running anything under 8.0, but anything 8.0+ is a nightmare.



Let's say I want a simple daily notification to pop up. It goes off once a day at a certain time, even if the application is closed. Exact timing isn't relevant:



    AlarmManager am =(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, alarmnotify.class);
PendingIntent pi = PendingIntent.getBroadcast(context, ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_DAY, pi);


On many devices supporting Doze this doesn't work and I have to use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() and refresh the alarm when it fires (annoying). But many more devices, this doesn't work either.



If the device is stock Android I can request an "ignore battery optimization privilege", but this isn't working for almost any of my testing devices because of some silly OEM battery manager that runs on top of the stock battery manager. Even Samsung has one of these now. And plus, Google does not recommend this approach, and it can get your app de-listed if they feel you don't need it.



    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);


Some devices are working if I use AlarmManager.setAlarmClock(), but this is silly, my app is not an alarm clock, I just want to display a notification.



I considered moving to FCM, but it's ridiculous to build client-server infrastructure over a simple once-daily alarm. Plus, that brings in numerous other considerations. The simplest: what if the user is offline?



I'm noticing this a major issue even in enterprise grade applications with millions of downloads. I have the same applications installed on a 7.0 and 9.0 device. The 7.0 device gets notifications and the 9.0 does not. What gives?



Is there a universal approach to handling alarms post-8.0, much like the first snippet was universal to all devices prior to 8.0?







android push-notification alarmmanager






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 5:07









AardvarkBlueAardvarkBlue

264




264













  • I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

    – Ankit
    Nov 13 '18 at 5:39













  • @Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

    – AardvarkBlue
    Nov 13 '18 at 5:49











  • I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

    – Ankit
    Nov 13 '18 at 6:15











  • @Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

    – AardvarkBlue
    Nov 13 '18 at 6:40



















  • I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

    – Ankit
    Nov 13 '18 at 5:39













  • @Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

    – AardvarkBlue
    Nov 13 '18 at 5:49











  • I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

    – Ankit
    Nov 13 '18 at 6:15











  • @Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

    – AardvarkBlue
    Nov 13 '18 at 6:40

















I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

– Ankit
Nov 13 '18 at 5:39







I had also stumbled upon a similar issue, on certain devices, if you remove apps from multi-tasking then it is considered force stopped. System will not trigger alarm for force stopped apps. I have android OnePlus 3T with 8.0.0 and this behaviour is replicated. Even Google keep and calendar fails to notify me on set time. The workaround however, that has been suggested to me at least is, to have a separate process for notification related tasks, So even when your app is killed that process can still trigger notifications.

– Ankit
Nov 13 '18 at 5:39















@Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

– AardvarkBlue
Nov 13 '18 at 5:49





@Ankit the OP6 on 9.0 is one of the devices I'm having the most issues with. Requesting battery de-optimization on this device is ignored because it has a proprietary batter optimizer on top of the standard one. A separate process to trigger notifications is a major battery drain, but maybe I'll give it a go. The only workaround I've determined is for users to manually turn off optimization for the app in question, which is very much not ideal.

– AardvarkBlue
Nov 13 '18 at 5:49













I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

– Ankit
Nov 13 '18 at 6:15





I am not sure how it will drain your battery though. That said, Telegram(the chat app) does the same thing apparently, they have a separate service(I assume it runs in a separate process) to receive push from FCM or whichever push service they are using. I forgot to mention that when app is swapped out from multitasking then even FCM push will not be received.

– Ankit
Nov 13 '18 at 6:15













@Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

– AardvarkBlue
Nov 13 '18 at 6:40





@Ankit That's the issue, there is no device-agnostic way to send push notifications of any kind if the app is dismissed from multitasking, and dismissing apps the user is finished with from multitasking is a common user interaction since Android came out.

– AardvarkBlue
Nov 13 '18 at 6:40












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274175%2fis-there-a-device-agnostic-way-to-handle-simple-recurring-push-notifications-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274175%2fis-there-a-device-agnostic-way-to-handle-simple-recurring-push-notifications-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values