Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service requestCode 0 #7

Open
excellentiam-prog opened this issue Sep 7, 2020 · 12 comments
Open

Service requestCode 0 #7

excellentiam-prog opened this issue Sep 7, 2020 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@excellentiam-prog
Copy link

Dear,

The App worked in my the tests of reboot and firing several alarms schedule at once, launching the app from the background, without having to open it.

After more tests. the issue is the inclusion of more alarms after the firing. The App works fine when I include several alarms at the moment I install it but after firing all alarms in it, the inclusion of more alarms is only firing when I opened the app. Looking at StackOverflow the causes of AlarmManeger are only firing when I launch the App, I found out about "pending request code". When I look at Service.class I find that the request code in PendingIntent.getActivity is 0, but in Alarm.class each alarm is stored as alarmId in two PendingIntent.getBroadcast.

I transferred the alarmId to Service intent and put FLAG_UPDATE_CURRENT in the getBroadcast but didn't work. But I would like to point out about the request code on the service.

@learntodroid learntodroid self-assigned this Sep 7, 2020
@excellentiam-prog
Copy link
Author

I did more tests and I believe that battery optimization has a role at killing the AlarmManager. I was reluctant to accept that because I tested another gitHub project that worked without this problem, but simpleAlarm is cleaner and easy to work it

@excellentiam-prog
Copy link
Author

@excellentiam-prog
Copy link
Author

@excellentiam-prog
Copy link
Author

I believe that the setAlarmClock instead setExact is the motive the other project worked even with battery optimization. Avoiding setRepeating too. The setAlarmClock method is the default in google Deskclock . https://developer.android.com/training/monitoring-device-state/doze-standby#restrictions

Something like

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

 alarmManager.setAlarmClock(alarmClockInfo, pendingIntent);

} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

alarmManager.setExact(android.app.AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);

} else {
alarmManager.set(android.app.AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
}

@learntodroid
Copy link
Owner

Wow. Thanks for sharing this @excellentiam-prog. It looks like AlarmManager's API is not respected by many different hardware manufacturers out there. I will need to look further into deskclock and the strategies you have suggested. This may take me a while. I will keep this issue open until I can find and implement a solution for this if there is one.

@learntodroid
Copy link
Owner

I have created a new code branch to track these bug fixes - https://github.com/learntodroid/SimpleAlarmClock/tree/alarms-doze-fix

@excellentiam-prog
Copy link
Author

Thank you. There is a project that uses AlarmSetClock and it doesn't need any permission in MIUI to fire the alarms. The MIUI is very restricted. The notification and the setalarmclock is in AlarmReceiver

https://github.com/PPartisan/Simple-Alarms

@excellentiam-prog
Copy link
Author

I did tests with PPartisan project, removing the setAlarmClock and leaving the setExact, and it worked, to my surprise.

I don't know why the MIUI is blocking your simple alarm (and others) but allowing PPartisan

@excellentiam-prog
Copy link
Author

excellentiam-prog commented Sep 15, 2020

I find one solution: AppKillerManager

Unfortunately, version 2.2.1 was discontinued. There a fork to version 2.2.5, but the readme is the same of 2.2.1, and more details is necessary to me. I tested the KillerManager.doActionPowerSaving(MyContext); in my Miui 10 and it worked. I don't know how to use "public void startDialog(KillerManager.Actions actions) {" which have the dialogs ...

https://github.com/tabebqena/AppKillerManager

@excellentiam-prog
Copy link
Author

excellentiam-prog commented Sep 15, 2020

I was recommended
Don't kill my app!

Seems more updated
https://dontkillmyapp.com/apidoc?fbclid=IwAR1Zbn66Ycq-1szy3nvJPVZtm9cqO9RWthnpHL8OFC9dQDp06k9S6KFm0AE

@excellentiam-prog
Copy link
Author

The AppKillerManager does not consume battery, it whitelists the app. I don't know if donkillmyapp makes the app alive the whole time, if true, it would be bad because consumes battery.

@learntodroid learntodroid added the bug Something isn't working label Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants