Difference between revisions of "MAP524/DPS924 Lecture 10"
(→Services & Broadcast receivers) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
We're only going to look at a small subset of this topic: Intent Services. | We're only going to look at a small subset of this topic: Intent Services. | ||
− | * We'll create an Intent Service as described [https://developer.android.com/training/run-background-service/create-service.html here]. | + | * We'll create an Intent Service as described [https://developer.android.com/training/run-background-service/create-service.html here]. The [http://developer.android.com/guide/components/services.html service overview] has a little too much information. |
+ | * They forgot to mention in the tutorial that you need to call a specific IntenService constructor, see [https://groups.google.com/forum/#!topic/android-developers/HVBnJ15amVc here]. | ||
* Then our activity (which has to be in the same project as the service) will call one function of the service with a parameter or two. | * Then our activity (which has to be in the same project as the service) will call one function of the service with a parameter or two. | ||
* Once the service is done its work - it will send a response back via an Broadcast Intent | * Once the service is done its work - it will send a response back via an Broadcast Intent | ||
** Which means we'll need to register to receive those in our activity. We'll create an IntentFilter and a BroadcastReceiver in Java and register them with LocalBroadcastManager.getInstance(this).registerReceiver(). | ** Which means we'll need to register to receive those in our activity. We'll create an IntentFilter and a BroadcastReceiver in Java and register them with LocalBroadcastManager.getInstance(this).registerReceiver(). | ||
+ | ** And since our activity may not be running at this point - we'll use a [http://developer.android.com/guide/topics/ui/notifiers/notifications.html Notification] to show that we got the message. | ||
= Reading incoming SMS = | = Reading incoming SMS = | ||
− | = | + | We can send a fake SMS to an emulator using telnet and receive it using a BroadcastReceiver. Follow [http://androidexample.com/Incomming_SMS_Broadcast_Receiver_-_Android_Example/index.php?view=article_discription&aid=62&aaid=87 this tutorial]. |
Latest revision as of 09:21, 23 November 2015
Services & Broadcast receivers
We're only going to look at a small subset of this topic: Intent Services.
- We'll create an Intent Service as described here. The service overview has a little too much information.
- They forgot to mention in the tutorial that you need to call a specific IntenService constructor, see here.
- Then our activity (which has to be in the same project as the service) will call one function of the service with a parameter or two.
- Once the service is done its work - it will send a response back via an Broadcast Intent
- Which means we'll need to register to receive those in our activity. We'll create an IntentFilter and a BroadcastReceiver in Java and register them with LocalBroadcastManager.getInstance(this).registerReceiver().
- And since our activity may not be running at this point - we'll use a Notification to show that we got the message.
Reading incoming SMS
We can send a fake SMS to an emulator using telnet and receive it using a BroadcastReceiver. Follow this tutorial.