Unable to send SMS before shutting down device - android

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?

Is there a way to prevent / turning on again the telephony service in order to send my SMS?
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.
is there another action similar to the SHUTDOWN event which I can use instead?
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).

Related

Android SMS receiving and handling

I know that it is possible to handle incoming sms on android and I think even me as a beginner can do that. But my question is: Will the app also run when the device is locked? I am working on an application that sends an email with the text and sender to a specific email address when the device received a SMS. But it also has to work when the device locked itself after a few minutes? Whats the best way to do that or is it already working by using the onRecieve method?
Thanks for any kinda help and please be kind I am quite new to programming :D
It's complicated...
As soon as an app is paused (that means : not displayed on the screen), it could be destroyed by the Android system to preserve battery or reduce CPU / RAM usage.
So : no, you have no guarantees the app will still be alive.
You can set a BroadcastReceiver to your AndroidManifest.xml and create a BroadcastReceiver class in your app. The onReceive() method will be called and the code you set in your class will be executed. Even if the app is not running at the moment the SMS is received.
But there's another issue : Deep Sleeping. To preserve battery, Android will turn off any battery-intensive systems when the device is not used for many hours. Battery-intensive systems includes : Wi-fi and Data. SMS is excluded from this list (but some constructors may include an option to disable SMS receptions when in Deep Sleeping, in this case, you have no option, just warn the user to not disable SMS receptions in Deep sleeping), gracefully.
That means implementing the onReceive() method will not be sufficient. You will need to wake up the device to enable Wifi and Data, allowing you to send an email.
So, to avoid this problem, extends a WakefulBroadcastReceiver. This is like a "normal" broadcast receiver, but it will wake up the device, and let it sleep again when the code is fully executed.

Receive Android GCM after restarting phone (without running related app)

I'm guessing this is a really rookie question, so I'm hoping someone can steer me in the right direction quickly & easily.
I have an app that receives GCM messages. The code that contains the GcmListenerService-derived class is located within my app. Because of this, the user MUST run my app after starting their phone in order for my listener to start listening (verified by restarting my phone, sending a test from Postman, and NOT getting the message / notification until I launch my app).
Do I need to create some type of service or something that will allow my app to get new GCM messages, even after restarting the phone (and not launching the app)?
Thanks!
Yes. You will need a broadcast receiver which listens on the BOOT_COMPLETED broadcast message and launches the push notification service. However, you still have to start the app once to register the receiver. It will also not work if the user force quit the app. There are some approaches, which also will restart the app automatically if the user killed the app, but I think it is a bad practice. In some circumstances the user wants to stop the app and keep it closed.

Android hidden service

Could someone please help me figurate how to make an app that has no icon and starts at the startup?
I want it to start in every startup and keep running all the time, because I want to Toast the name of the sender each time there's an incoming SMS.
I'm not sure what you mean by "hidden" as the O/S generally tries to avoid allowing you to hide behavior from the user. What you want to do is discussed in this question Trying to start a service on boot on Android. That will enable you to launch a service and then by watching for the appropriate intents related to SMS messages you can create the toasts you desire.

How to start/stop custom built application on remote Android device

I have written an app in Eclipse and now I just need to add an additional method, but I'm wondering how to do it.
Method should listen to incomming messages somehow, and when SMS arrive to device it should start/stop my current app running in background.
So, I send SMS to device with specific content in message (e.g START123) and when device receives it, content application will automatically start and perform all further tasks on it.
Any idea/coding on how to accomplish this is welcome. :)
Thanks and regards.
https://stackoverflow.com/a/8720582 do your work from a service.
Don't forget to catch on boot if your app should run after reboots.

Android Service that monitors user activity

Is it possible for a background service to log every action of the user on his device? I just want to check if our devices are vulnerable to such actions.
Yes it is. But depending on what your app wants to monitor, you don't need to run a Service just to constantly monitor the user's actions. All you need is a BroadcastReceiver that listens to Intents fired by the system when specific phone events occur.
For example, I once built a mobile app that logs all the user's sent SMSes, detects incoming SMS, incoming and outgoing calls, and bytes of data sent and received over 3G and WiFi. Shameless plug, I've posted some tutorials on how to do it in my website: http://www.mattquiros.com/blog
You could also monitor the other way. Looking at the Browser class and monitoring processes and what tasks are running using ActivityManager.

Categories

Resources