0

If I set a timer in the default Android clock app, then it has the following behavior when the time runs out:

  1. If the phone is unlocked, a pop-up comes up allowing you to stop the alarm or navigate back to the app.
  2. If the phone is locked (including if the screen is off), the screen turns on and you're taken to a special Activity to stop the alarm.

What is the best way to reproduce both of these behaviors in my own app? I've been copy-pasting various magical incantations involving AlarmManager for the second, but nothing is working. None of the questions that have come up when Googling things like "bring Activity to front" or "wake up phone" seem to be what I need.

Jack M
  • 4,769
  • 6
  • 43
  • 67

1 Answers1

1

This can't be done, and it's by design. There are 2 separate problems, and they're both impossible to implement.

  1. Google has progressively disabled the ability to launch activities without user interaction in all recent API versions. They also disabled "springboard" behavior, where background services and/or receivers try to start activities from the background. You're supposed to use notifications to let the user know what you're trying to do, and when they interact with that notification, then your activity can be launched
  2. There is absolutely no app, unless you have a custom ROM or a rooted phone, that can bypass the lock screen. It's a security issue, and the idea is the same as in the previous case -- you need to notify the user, and if they interact with the notification, they can be prompted to unlock their phone and your activity will launch
user496854
  • 6,461
  • 10
  • 47
  • 84
  • I found [this question](https://stackoverflow.com/questions/40249702/how-to-show-popup-dialog-over-lock-screen-like-android-alarm-clock-when-getting) about exactly this issue, and two people have posted (fairly useless, unfortunately) answers seemingly implying that it is possible. Was this stuff deprecated since 2016? – Jack M Sep 28 '22 at 14:59
  • That link really doesn't specify anything, and I don't know about 2016, but in much earlier versions of Android, there were technically ways that people created custom lock screen apps. As far as I remember, you either had to have a rooted device, or you had the user disabled their actual lock screen, and then recreate lock screen functionality in your own app. Either way, you definitely can't do that now – user496854 Sep 28 '22 at 20:16
  • To be clear, we agree that the default alarm clock app does do this, right? It just presumably requires system app permissions or something. – Jack M Sep 28 '22 at 21:32
  • Yes, but I don't know how they do it – user496854 Sep 28 '22 at 23:06