Android Service that monitors user activity - android

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.

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?

Unable to send SMS before shutting down device

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).

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.

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: Infinitely running Service for receiving events?

I have a requirement that my app, can receive events (e.g. messages) from server any time (even if app is not running). So do I need to create an infinitely running service to listen for these events?
This to me seems similar to Email apps in Smartphones, like whenever you receive a new email(event in my case), its able to show notifications and also able to update my list adapter whenever I receive an event.
But I dun know how will I implement this?
You should take a look at C2DM (push-messages):
http://code.google.com/intl/sv-SE/android/c2dm/index.html#intro
it allows a server to send messages to devices at any time.
From the link:
Here are the primary characteristics of Android Cloud to Device
Messaging (C2DM):
It allows third-party application servers to send lightweight messages to their Android applications. The messaging service is not
designed for sending a lot of user content via the messages. Rather,
it should be used to tell the application that there is new data on
the server, so that the application can fetch it.
[...]
An application on an Android device doesn’t need to be running to
receive messages. The system will wake up the application via Intent
broadcast when the the message arrives, as long as the application is
set up with the proper broadcast receiver and permissions.
[...]
Events from server are called "push notifications" and are implemented via "Cloud 2 device messaging" (C2DM). On the mobile side these messages are submitted as broadcast events (see BroadcastReceiver). For a complete example see some tutorials: Google, Vogella or here on Stackoverflow
I think you have to start a Service as soon as the device booted. There is a good tutorial here how to achieve this.

Categories

Resources