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.
Related
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
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.
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.
Hey i wanna know if android apps are abble to perform some work like send data to there server accessing system tool and using all permissions it have requested for?
The scenario is, i install an app from google play successfully. I won't open that app. But i want it to contact its server and exchange some data and use all other permissions. Is this possible?
You can try it using broadcast reciever no need to run the app just regester for some broadcast reciever and wait for that to broadcast to your reciever and you can call whatever task you want in that reciever class... i will make it one and test it and post the github link in comment
No, the app needs to be run once in order for you to perform the specified actions, merely installing would not be enough.
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.