Android NFC Proof of Concept - android

I have an idea for an android NFC application but am not entirely sure how to implement it.
I want to be able to have an application that is always on (starts on bootup) and the user cannot exit out of the application. I want two have two phones with NFC enabled. One phone is set up as a listener, the other phone is set up as a sender. Both of these devices will have a code. Sender inputs a code (1234), and the listener has a code (123). If the sender puts the phone up to the listener, and the code is incorrect (1234 instead of 123). The device will lock. The only way the device can unlock is if the sender has the same code as the listener.
I don't want code samples.. I just want an explanation of how you would go about doing this.. and if it is possible.

Basically you need your app to start a service after the phone has booted, use BroadCastReceiver which takes action with the BOOT_COMPLETED intent. When that broadcast receiver has been notified of the boot completion you'll start the service which will handle your nfc jobs.

Related

I want to use accelerometer sensor to message saved number from my app by not launching that app

In my app I used sharedpreferences to save my friends number.
When I need to message them it needs to open my app and then shake to use accelerometer sensor, then message goes.
Here I want to send messages without lunching my app by shaking my phone.
How I can do this?
Interesting question. You should try a broadcast receiver with appropriate filters or a background service. There may be a better approach, just my initial thought.
BroadcastReceiver
https://developer.android.com/reference/android/content/BroadcastReceiver.html
(if the action of sending takes too long, you may prefer to couple this with a wakeful broadcast receiver AND delegating the work to an Intent Service: https://developer.android.com/training/run-background-service/create-service.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.

What is the difference between Broadcast Receiver and service?

I wrote program for broadcast receiver and service, but i confused in the manifest file there is some ground work to register service and receiver, will any one give me clear idea about this? Thanks in advance.
Service
It is used when you want to do something in background, any long running process can be done using Service in Background.
This will be running always in background even if the application closed
For example, you want to play music when your application gets close. In that case service will be running in background with music.
BroadcastReceiver
It is used when you want to fire some stuff or code during some event. For example, event can be on Boot of Device.
Usually system will send some info which can be recieved by your app if you would wish to ,by registering. And you can do something what you want when that thing happens by using onReceive method. Example is the system will send BroadcastReceiver when new sms arrives or Booting done
for example, If you want to perform something when device Boots, date and time changed etc.
A service is used to perform long running operations without user interaction or to supply functionality to other applications.
A Service needs to be declared in the AndroidManifest.xml via
a <service android:name="yourclasss"> </service> and the implementing class
must extend the Service class or one of its subclasses.
To start Services automatically after the Android system starts you can register
a BroadcastReceiver to the Android android.intent.action.BOOT_COMPLETED system
event. This requires the android.permission.RECEIVE_BOOT_COMPLETED permission.
For more details, check this http://www.vogella.com/articles/AndroidServices/article.html#pre_broadcastreceiver
A broadcast receiver is an Android component which allows to register for system or application events. All registered receivers for an event will be notified by Android once this event happens.
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
It'll be very long to explain it all here
I've got 2 great tutorial links from vogella
Broadcast Receiver
Service
if you have further question after reading the tutorial feel free to ask me in the comment :)

Launching an app with bluetooth

I am working on an android app that needs to be able to toggle a setting on one phone after a bluetooth message from the other. I need to know how to make it so that when the message is received, my app opens to handle the request. Similar to how nfc tags work, you can launch an app with it, then read the data on the tag. I need to be able to launch my app, then read the data inside the bluetooth message. Thanks for the help.
The message can't launch an app directly, you have to design a background service wich listen bluetooth message and trigger the app.
Moreover, you can start this service at start up with a broadcast receiver

How do you ship/enable a separate service in android?

Is it possible to launch a service whenever a phone is booted up?
My question is that, say, I want to have a background service running in the background when the phone is booted up, once it receives a notification, say, a stock price is now above a certain price, then the user will get notified and in the notification center it will launch the actual app if a user chooses to click on it.
My question is, where do I put the tag? In my application manifest? but again, I only want the service to run automatically without user launching my app.
I see here two possibilities for you:
Is the same approach that was proposed by #triad. You can have a broadcast receiver that will start your service.
You can use push notifications. As I understand from the question it is possible in your case. I guess using push notifications will be cheaper (in the context of power) in your case.

Categories

Resources