Waking Android over network - android

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.

Related

Is it possible to trigger a notification in another android phone using broadcastreceiver?

I'm new in android development, and need some help and guidance in triggering my notification in my application. I manage to read some documentation about BroadcastReceiver where in it broadcast an announcement and another app can receive that announcement and trigger something to happen(like popping out a notification). I tried doing it, wherein I have 2 (two) application in 1 (one) android device and it worked. But when I try separate the 2 (two) application and install it separately into 2 (two) android device and try to send the broadcast, the receiver didn't manage to receive the broadcast. Then I tried to do more research and saw that BroadcastReceiver is a "System-Wide" broadcast, means (correct me if I'm wrong) it will only work inside 1 (one) android device. So my question is now, is there anyway to make the BroadcastReceiver send the broadcast in the network so that if an android device with a receiver can receive the sent broadcast? if it's not possible, is there another way to trigger notification in 1 device using another device w/o using the FCM/GCM?
PS:
The reason why I don't want to use FCM/GCM is that I'm trying to do this in an adhoc network, wherein internet connection is not present. And I'm not sure how FCM/GCM will behave w/o the internet connection. I appreciate any help. Thanks you.
You can setup a server in a background service on one of the devices and send data to if from the other device, and then have that service create a notification when it gets data.
If you want the devices to automatically be able to discover each other try using the network discovery service. https://developer.android.com/training/connect-devices-wirelessly/nsd.html

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.

Is there anything like GCM for offline communication?

Seems like GCM for Android only works if there is internet. Wondering whether there are any other methods (maybe via text/call, etc) that could trigger a background service which would send back user's location (via text, etc. or maybe keep it until connection is present)?
My two concerns are:
How much can I do without the user doing anything (or even knowing it's happening... assuming they downloaded the app already and gave appropriate permissions)?
How would I send the data back? (if via text, Reason #1 seems to be a bigger matter)
Here is an alternate solution but it is costly,
Create Broradcast Receiver that listen for incoming SMS.
In any sms with start some predefined word like "START_SERVICE" is arrived then fire the broadcast and start the service you want.
You may use normal SMS scheme or any bulk sms kind of service.
The above scenario doesn't require any INTERNET connection at all.

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.

Intercept incoming flash messages on android mobile

can anyone help me to intercept the incoming Flash messages (specially the ones from the telecom company, where they send our current balance after some activity like message sent).
My application deals with sending SMSes in bulk and I don't want the flash message popping now and then. So is it possible on Android ?
EDIT: Everyone says its not possible above Android 1.6 but I found a similar App on Google Play but I want the source of that kind of App. Please Help.
Edit: More than a year has passed and still I didnt got the solution. Can anyone help to resolve this thread..??
Might depend on the channel [of communication] used by your service provider. I guess they don't use SMS, probably they use WAP/PUSH or some pre-installed provider app for the notifications, which makes this harder to block. If it was SMS, you'd definitely have lots of ways to block their notifications, but in this case, I doubt there might be an easy / direct way to do this.
Flight Mode should ideally block telco / service-provider messages / notifications, but then this also blocks your connectivity, right? So, am not so certain on this one. Isn't there a way to opt-out of service provider notifications, maybe via a ussd routine? I've heard of this once...
Flash sms it is the same as usual sms except data coding flags. It has "class 0" indication in DCS.
For details about sms coding see: GSM 3.38 specification / 4 SMS Data Coding Scheme.
Some fragment from spec about it
When a mobile terminated message is class 0 and the MS has the capability of displaying short messages, the MS shall display the message immediately and send an acknowledgement to the SC when the message has successfully reached the MS irrespective of whether there is memory available in the SIM or ME. The message shall not be automatically stored in the SIM or ME.
So, in most cases, phone just displays this message and skips usual chain of actions.
Probably, you can't catch this message with usual API... probably you need deep hook and rooted device.
[Or may be just switch off this service by calling customer support?]

Categories

Resources