Differences

This shows you the differences between two versions of the page.

Link to this comparison view

osp:lectures:lecture-connectivity [2016/11/02 14:40]
vlad.traista [Practical]
osp:lectures:lecture-connectivity [2016/11/06 18:57] (current)
laura.gheorghe [Lecture]
Line 9: Line 9:
  
   *{{:​osp:​lectures:​lecture-connectivity.pdf | Lecture Slides}}   *{{:​osp:​lectures:​lecture-connectivity.pdf | Lecture Slides}}
 +  *{{:​osp:​lectures:​5.connectivity_notes.pdf | Lecture Notes}}
  
 {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-connectivity.pdf}} {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-connectivity.pdf}}
Line 16: Line 17:
 === Resources === === Resources ===
  
-=== Task 1 - Downloading remote content === +=== Task 1 - Downloading remote content ​(1p) === 
-Create a new project with a blank main Activity. Add an EditText, a Button and a TextView to the Activity'​s layout. When the user enters ​URL into the EditText and clicks the Button download the remote HTTP content at that URL and display it into the TextView.+Create a new project with a blank main Activity. Add an EditText, a Button and a TextView to the Activity'​s layout. When the user enters ​an URL into the EditText and clicks the Button download the remote HTTP content at that URL and display it into the TextView.
  
 By design, the Android framework will not allow long-running or potentially blocking operations (such as network operations) to be carried out on the main UI thread. As such, within the onClick() method of the Button we want to start a new thread in which to download the HTTP data.  By design, the Android framework will not allow long-running or potentially blocking operations (such as network operations) to be carried out on the main UI thread. As such, within the onClick() method of the Button we want to start a new thread in which to download the HTTP data. 
Line 76: Line 77:
 </​note>​ </​note>​
  
-=== Task 2 - Getting the current location ===+=== Task 2 - Getting the current location ​(2p) ===
  
 For this task, you will need to have enabled either the GPS of your mobile device or an active WiFi connection (or both). For this task, you will need to have enabled either the GPS of your mobile device or an active WiFi connection (or both).
  
-On Android, ​there the location can be gathered using three providers:+On Android, the location can be gathered using three providers:
   * GPS provider which uses the GPS driver of your mobile device to track your connection (it is slow and not very precise)   * GPS provider which uses the GPS driver of your mobile device to track your connection (it is slow and not very precise)
-  * network provider which relies on having an active ​internet ​connection (it has high levels of accuracy)+  * network provider which relies on having an active ​Internet ​connection (it has high levels of accuracy)
   * passive provider which relies on having the current location determined by other applications   * passive provider which relies on having the current location determined by other applications
  
Line 90: Line 91:
 In order to get the current location, the main activity will have to implement the [[https://​developer.android.com/​reference/​android/​location/​LocationListener.html|LocationListener]] interface which provides methods for detecting when the location has changed or when a location provider has been enabled or disabled. In order to get the current location, the main activity will have to implement the [[https://​developer.android.com/​reference/​android/​location/​LocationListener.html|LocationListener]] interface which provides methods for detecting when the location has changed or when a location provider has been enabled or disabled.
  
-Getting the location requires sending a request to the location providers to determine the current location. The request is sent using a [[https://​developer.android.com/​reference/​android/​location/​LocationManager.html|LocationManager]] object. Make sure to send a request for every active network provider. ​Th request will also need a time between updates and a minimum distance to be considered for updating the location. Set these values to 10 minutes ​and 50 meters. These requests will be sent upon clicking the button.+Getting the location requires sending a request to the location providers to determine the current location. The request is sent using a [[https://​developer.android.com/​reference/​android/​location/​LocationManager.html|LocationManager]] object. Make sure to send a request for every active network provider. ​The request will also need a time between updates and a minimum distance to be considered for updating the location. Set these values to 1 minute ​and meters. These requests will be sent upon clicking the button.
  
 The LocationListener interface offers a callback through which the user can perform operations if the location coordinates have changed. Implement this callback to set the text of the TextView object to the current coordinates. The LocationListener interface offers a callback through which the user can perform operations if the location coordinates have changed. Implement this callback to set the text of the TextView object to the current coordinates.
  
 <note warning> <note warning>
-Take into account the fact that the location updates take time. Therefore the TextView will not be changed immediately,​ it will be affected ​after 10-12 seconds if a network provider was used to determine the location or more than 20 seconds if a GPS provider is used.+Take into account the fact that the location updates take time. Therefore the TextView will not be changed immediately,​ it will be changed ​after 10-12 seconds if a network provider was used to determine the location or more than 20 seconds if a GPS provider is used.
 </​note>​ </​note>​
  
-=== Task 3 - Getting the last known location periodically ===+=== Task 3 - Getting the last known location periodically ​(2p) ===
  
 The LocationManager object also offers a method through which you can get the last known location on the device (it could be the current one or an outdated one). We will want to periodically log the last known location. The LocationManager object also offers a method through which you can get the last known location on the device (it could be the current one or an outdated one). We will want to periodically log the last known location.
Line 140: Line 141:
 Occasionally press the button that updates the current location and see if the changes are reflected in the logs. Occasionally press the button that updates the current location and see if the changes are reflected in the logs.
  
-=== Task 4 - Scaning for Bluetooth devices periodically ===+=== Task 4 - Scaning for Bluetooth devices periodically ​(2p) ===
  
 Similar to Task 3, we will want to log the detected Bluetooth devices periodically. Similar to Task 3, we will want to log the detected Bluetooth devices periodically.
Line 191: Line 192:
 Take into account the fact a Bluetooth discovery lasts between 12 and 15 seconds. Take into account the fact a Bluetooth discovery lasts between 12 and 15 seconds.
  
-=== Task 5 - Scaning for WiFi devices periodically ===+Add two buttons to the main activity: 
 +  * one that starts the Bluetooth alarm  
 +  * one that stops the Bluetooth alarm
  
-In a similar fashion to Task 3 and Task 4, implement an alarm manager that periodically scans the WiFi network ​for WiFi devices (Hint: [[https://​developer.android.com/​reference/​android/​net/​wifi/​WifiManager.html|WiFiManager]]).+=== Task 5 - Scaning ​for WiFi devices ​periodically ​(3p===
  
-=== Bonus - Wakelocks ===+In a similar fashion to Task 3 and Task 4, implement an alarm manager that periodically scans the WiFi network for WiFi devices and prints their MAC address. (Hint: [[https://​developer.android.com/​reference/​android/​net/​wifi/​WifiManager.html|WiFiManager]]).
  
-TODO+Add two buttons to the main activity: 
 +  * one that starts the WiFi alarm  
 +  * one that stops the WiFi alarm
  
 +=== Bonus - Wakelocks (3p) ===
 +
 +When a mobile device has its display closed, it usually enters into sleep mode which means that the CPU is inactive. Once the display is closed, most applications do not perform actions or execute operations as frequently as they do when the display is on. However there are applications that require having the CPU active even when the screen is closed. This can be achieved using [[https://​developer.android.com/​reference/​android/​os/​PowerManager.WakeLock.html|wakelocks]]. Wakelocks are generally used within gaming applications so that the screen is active all the time.
 +
 +When the device has its display closed, the wireless driver is also affected by the sleep mode. Performing a WiFi scan in sleep mode would yield the results from the last time when the device was active. ​
 +
 +For this task, you will have to add a wakelock to the WiFi scan alarm manager. This wakelock will have to activate the display and disable the lockscreen if it is present.
 +
 +<note warning>
 +Take into account the fact that a WiFi scan lasts around 15-20 seconds.
 +</​note>​
osp/lectures/lecture-connectivity.1478090439.txt.gz · Last modified: 2016/11/02 14:40 by vlad.traista
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0