Android SMS receiving and handling - android

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.

Related

Receiving (and sending) USSD messages on Android - application in background, screen locked

Found some SO Q&A about how to send and receive USSD messages (exchanged with the cellular network) on Android. I understand that one needs to register a BroadcastListener to receive USSD message, but have further questions (so far, admittedly theoretical i.e. without having attempted to write code for this).
On Android it is possible (and if so what are the specific things to take care of) so that my application gets to receive the USSD message from cellular network, even though it is not the foreground application, and even though the screen is locked, or when the device is in sleep-mode ?
From what I have read so far, it seem that I'd need a background service that registers the BroadcastListener for USSD message, that can then send a local Notification, to wake up the application which can offer UI for interaction with user. Is that correct ?
Note that the desired behaviour is somewhat analogous to GCM/FCM Notification being used to wake-up an application from sleep (post user interaction responding to the Notification). However, in this case there is no GCM/FCM, but only USSD message from the network.
USSD transaction (Sending and Receiving) is not yet supported on android app, you can follow the issue in google bug tracker: https://issuetracker.google.com/issues/36905980
and also similar question was asked Call (and get the response for) a USSD Code, in the background?

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.

Waking Android over network

I'm a newbie when it comes to Android programming, but I've been doing a bit of digging in the SDK. I'm trying to create an application which allows me to wake the phone via a message sent over the network.
Ideally, I will have a java program on my computer which has a button I can push to wake the droid. I've read that a 3g socket can do this, but given that most providers use NAT, this doesn't seem like a good route.
I'd like to stay away from leaving the phone running with a wakelock, since that seems like it would kill the battery life. Is there any way to have the droid wake on an incoming network event? If not, what do you think the best way would be to approach this problem?
You can utilize C2DM messaging as well. You can initiate a wakelock when the C2DM message is received, do what you need and then release the lock.
C2DM Documentation
The only way that I can think of would be to create a BroadcastReceiver and register it for SMS_RECIEVED than send the device an SMS with some unique identifier of your choosing. The BroadcastReceiver will read incoming SMS and if it finds the unique identifier then it will wake lock the device and do any work (this you can handle in a Service). If you want to actually wake the device screen, that is a well-covered topic, but here is one post on it. Once you've accomplished your work, you could then delete the SMS if you don't want it cluttering the inbox. Note that you would need the READ_SMS and RECEIVE_SMS permissions in your Manifest.
Sadly this isn't as elegant as a cool Wake on LAN type feature, but it should work nonetheless.
Let me know if you need an clarifying or examples.

Android - How to receive the BOOT signal with an application installed on sdcard?

I need to start a notification service for an application when the device boots. I have implemented a BroadcastReceiver that listens to the boot signal in order to start the service.
However, this works only if the application is not installed on sdcard (because the signal is received before the sdcard is mounted). Is there any solution to keep installing the application on sdcard and yet still receive that signal?
Any hack for this?
Let me know!
Thanks!
You could either:
Register an account in the AccountManager and set up a sync service (tutorial1, tutorial2) -- Android will start your service automatically; or
Listen for some other broadcasts as well (such as screen off / screen on) and test whether you need to start your notification service or not.
I realize these are not easy / convenient solutions, but they're the only ones I can think of. If anyone knows a better solution, I'll be happy to upvote :).
Another solution (which could eventually be used in conjunction with one of the above) is to start your service (or check if it needs to be started) when your application is launched from the application launcher (i.e. when the "main" activity is started).

Categories

Resources