Android Question Play azan (call to prayer) daily at specific times: can't get it to work

MegatenFreak

Active Member
Licensed User
Hey guys.
As the title says, I wanna build an app that does one simple thing: I'll give it the prayer timetable with specific times of the day, and it will play the azan audio during those exact minutes.
I've dug everywhere in the forums and tried all the following without success:
* Using services and receivers
* Using a foreground service following Erel's "Location Tracker" example and a spin-off of it designed to play music.
The receiver is far from accurate, and the foreground service works fine and accurately with the persistent notification up there, but once the user clears open/recent apps, the notification is also killed. I've tried and tried, without success.
Am I missing something here?
Thanks a lot in advance.
 

drgottjr

Expert
Licensed User
Longtime User
hard to know what you're missing since we don't know exactly what you've
done. i would hope to see simple code for a simple app. please archive the
project and post it. since you claim to have tried various methods, let's
pick the one most likely to succeed: the foreground service.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the only way i could stop the "music" was to force close the app from the settings dialog.
hitting the "back" key didn't stop it, tapping on the notification didn't stop it. tapping on
the recent apps just brought the app back into the foreground. not sure what the problem
you had was. i tested it on a pixel 3a, android 12. getting something to run at an exact time
is a different proposition and takes other things into account (like battery saving, permissions, etc.
plus there are things to look at like "permissiontowakewhileidle"). erel has an example. maybe
you hadn't seen that one. android basically doesn't want you running stuff at an exact time. you
(or your users) may have to turn off battery saving (from settings) to get it to work.
 
Upvote 0

MegatenFreak

Active Member
Licensed User
the only way i could stop the "music" was to force close the app from the settings dialog.
hitting the "back" key didn't stop it, tapping on the notification didn't stop it. tapping on
the recent apps just brought the app back into the foreground. not sure what the problem
you had was. i tested it on a pixel 3a, android 12. getting something to run at an exact time
is a different proposition and takes other things into account (like battery saving, permissions, etc.
plus there are things to look at like "permissiontowakewhileidle"). erel has an example. maybe
you hadn't seen that one. android basically doesn't want you running stuff at an exact time. you
(or your users) may have to turn off battery saving (from settings) to get it to work.
Thank you so much for the testing the code and the reply.
* About stopping it or getting to play at exact times, I'll handle those later; right now I'm only focused on getting it to "stay" up there and stay active.
* I've tried turning off batter saving (which is necessary on my phone otherwise apps get killed left and right!) but I didn't see any other permission requirements in Erel's example, other than ACCESS FINE LOCATION which was for the GPS thing and I didn't need it.
So basically what I want is for the notification to persist up there, but when I do the close recent/open apps thing, which is a constant habit of mine, it gets killed. Is there another permission necessary that I'm not aware of? (I didn't notice a "permissiontowakewhileidle" in the posts, but even if it does what it does, it won't matter if the service is killed and gone).
Also, will it help if I used a widget to keep the service running?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i suppose a little obsessive/compulsive behavior has its place,
but if you're going to keep killing apps, you make things difficult
(i'm guessing you'd figure out a way to kill your widget, too).

afaik, the only way to get an un-running app running is with a static broadcast
receiver (there are 2 types, but we only use 1 in b4a).

that gets us in battery optimization and permissions territory.

just to clarify where we stand: if you don't kill your example, it just keeps
running, right?

i'll find the example i mentioned and revert.


edit: now that i think about it, a home screen widget might work for you. erel's example is basically plug'n'play. he's got it set to do something every hour, might that can be overridden. the thing runs all the time (automatic startup on boot) and when the time is right, it posts something on the home screen. i'm guessing it could play audio.
 
Last edited:
Upvote 0

MegatenFreak

Active Member
Licensed User
i suppose a little obsessive/compulsive behavior has its place,
but if you're going to keep killing apps, you make things difficult
(i'm guessing you'd figure out a way to kill your widget, too).

afaik, the only way to get an un-running app running is with a static broadcast
receiver (there are 2 types, but we only use 1 in b4a).

that gets us in battery optimization and permissions territory.

just to clarify where we stand: if you don't kill your example, it just keeps
running, right?

i'll find the example i mentioned and revert.


edit: now that i think about it, a home screen widget might work for you. erel's example is basically plug'n'play. he's got it set to do something every hour, might that can be overridden. the thing runs all the time (automatic startup on boot) and when the time is right, it posts something on the home screen. i'm guessing it could play audio.
What example of Erel's are you referring to? The original widget tutorial from 2011 shows a media player, but I figured since it's a decade old, things must have changed in that area?
 
Upvote 0
Top