I'm developing an app which needs to send an SMS if / when the device shuts down.
In order to receive the action I'm using android.intent.action.ACTION_SHUTDOWN and android.intent.action.QUICKBOOT_POWEROFF actions, and it works perfectly well. In fact, the method I'm using to send the SMS is also working (as I have used it multiple times in other apps).
The problem I'm facing is that when I receive the SHUTDOWN action the telephony service is already off, so the SMS is unable to be sent and it remains queued waiting for a retry.
Is there a way to prevent / turning on again the telephony service in order to send my SMS?
In case it's not possible, is there another action similar to the SHUTDOWN event which I can use instead?
You are welcome to make your own customized build of Android that sends an SMS message as part of its shutdown process. Then, you can try to package that customized build of Android into a custom ROM for a particular piece of hardware.
If you are asking whether an app can do that on arbitrary hardware, the answer is no.
You can ask the user to tap on something related to your app (e.g., a
Notification) before shutting down the device.Otherwise, I am not aware of some other event that not only tells you that the device is shutting down but also lets you block that shutdown process until you decide it is time to proceed (e.g., after sending an SMS, after forcing a ransomware payment).