Unit 5 - Practice Quiz
1 What is the primary purpose of Bluetooth technology in mobile devices?
2 In the context of Bluetooth, what does 'BLE' stand for?
3
Which permission must you declare in the AndroidManifest.xml file to allow an application to create network sockets and access the internet?
4 Why is it important to perform network operations on a background thread instead of the main (UI) thread in Android?
5 What is the process of searching for nearby Bluetooth devices that are broadcasting their presence called?
6
Which method in the BluetoothAdapter class starts the process of searching for nearby Bluetooth devices?
startDiscovery()
findDevices()
searchBluetooth()
scanForPeripherals()
7 What is a 'paired' or 'bonded' Bluetooth device?
8
Which Android method returns a set of BluetoothDevice objects representing the devices that are already paired with the local device?
getPairedDevices()
getBondedDevices()
getConnectedDevices()
listSavedDevices()
9 What is a major advantage of using Wi-Fi for companion device pairing over Bluetooth Classic?
10
What is the purpose of the CompanionDeviceManager API in Android?
11
In Bluetooth communication, what is a BluetoothSocket primarily used for?
12 Which communication protocol is commonly used in Android to create a reliable, stream-based connection over Bluetooth, similar to TCP?
13 Which type of sensor measures the acceleration forces acting on a device, including the force of gravity?
14 What does a gyroscope sensor measure?
15 To implement a feature that detects when a user 'shakes' their phone, which sensor would be most suitable to use?
16 Which sensor helps a device determine its orientation relative to the Earth's magnetic north, acting like a digital compass?
17 What is the most common use case for a proximity sensor in a smartphone?
18 Which sensor would you use to measure the ambient air pressure?
19 A photometer, also known as a light sensor, is used to measure what?
20 Which category of sensors do the thermometer, barometer, and hygrometer belong to?
21 An Android app needs to connect to a heart rate monitor to stream data continuously. Which Bluetooth profile is most suitable for this use case, prioritizing low power consumption?
22 In a Bluetooth Classic connection between a smartphone (master) and a speaker (slave), which device is responsible for initiating the connection and managing the piconet timing?
23
When establishing a Bluetooth connection using BluetoothSocket, which method call is blocking and should not be executed on the main UI thread to avoid an Application Not Responding (ANR) error?
bluetoothAdapter.getRemoteDevice(address)
device.createRfcommSocketToServiceRecord(uuid)
socket.close()
socket.connect()
24
Your app is designed to receive a stream of sensor data from a connected Bluetooth device. Which component is essential for handling incoming data asynchronously from the BluetoothSocket's InputStream in a separate thread?
BroadcastReceiver listening for ACTION_ACL_CONNECTED
InputStream within a background thread
ContentProvider to query the data
IntentService that reads the stream once and then stops
25
To create a secure server-side BluetoothServerSocket for an app that needs to accept incoming connections, what is the correct method to call on the BluetoothAdapter?
listenUsingInsecureRfcommWithServiceRecord(name, uuid)
startDiscovery()
createRfcommSocketToServiceRecord(uuid)
listenUsingRfcommWithServiceRecord(name, uuid)
26
To discover new Bluetooth LE devices, your app starts a scan using BluetoothLeScanner.startScan(). To ensure the scan doesn't drain the battery, what is the recommended practice?
Handler to stop the scan after a predefined period (e.g., 10-15 seconds)
SCAN_MODE_LOW_POWER and run it continuously
27 An app needs to find nearby smartwatches that advertise a specific service UUID. How can you configure the Bluetooth LE scan to only return devices that match this criterion, thus saving power and processing time?
ScanFilter with the required ServiceUuid and pass it to startScan()
BroadcastReceiver for ACTION_FOUND
BluetoothDevice object for the service
28 How does an Android app retrieve a list of Bluetooth devices that have already been paired with the phone without initiating a new discovery scan?
bluetoothAdapter.getBondedDevices()
Settings.Secure content provider
bluetoothAdapter.startDiscovery() and filtering for bonded devices
BroadcastReceiver for ACTION_BOND_STATE_CHANGED
29 When a user pairs a new Bluetooth device through the system settings while your app is running, which broadcast intent action should your app listen for to update its list of paired devices dynamically?
BluetoothDevice.ACTION_FOUND
BluetoothDevice.ACTION_BOND_STATE_CHANGED
BluetoothDevice.ACTION_ACL_CONNECTED
BluetoothAdapter.ACTION_DISCOVERY_FINISHED
30 What is the primary advantage of using the Companion Device Manager (CDM) for pairing with a Wi-Fi device over a traditional Wi-Fi Direct or Soft AP approach?
31
To initiate companion device pairing, an app needs to create an AssociationRequest. Which piece of information is crucial to include in this request to filter the type of device the user can select from the system-provided dialog?
DeviceFilter specifying characteristics like a service UUID or device name pattern
32
An app is using the Network Connectivity API to connect to a smart home device via Wi-Fi. It needs to maintain this connection even if the Wi-Fi network has no internet access. Which capability should be removed from the NetworkRequest.Builder?
NET_CAPABILITY_NOT_ROAMING
NET_CAPABILITY_VALIDATED
NET_CAPABILITY_TRUSTED
NET_CAPABILITY_INTERNET
33 Your app uses Wi-Fi Aware to discover and connect to a nearby device. After a successful discovery, what is the next step to establish a direct, bi-directional data path between the two devices?
WifiP2pManager and initiate a group
ServerSocket and the other creates a Socket using the Network object obtained from the Wi-Fi Aware session
34 An app needs to detect the device's orientation in 3D space, including its heading (azimuth) relative to magnetic north. Which sensor or sensor combination provides the most direct and stable data for this purpose?
TYPE_GRAVITY alone
TYPE_ROTATION_VECTOR
TYPE_ACCELEROMETER alone
TYPE_GYROSCOPE alone
35
To implement a "shake to undo" feature, you need to detect a sudden, sharp movement of the device. Which approach using the accelerometer data (SensorEvent.values) would be most effective?
36 You are building a game where the user tilts the device left and right to control a character. You notice the controls are jittery. To smooth the input from the accelerometer, what signal processing technique should you apply to the sensor readings?
37
An application requires the device's orientation relative to the Earth's magnetic field to build a compass. Which sensor type should be registered with the SensorManager to get the raw geomagnetic field data?
TYPE_GRAVITY
TYPE_GYROSCOPE
TYPE_PROXIMITY
TYPE_MAGNETIC_FIELD
38
To determine the device's absolute orientation (including North, East, Up), you need to combine data from two specific sensors. Which pair is used by SensorManager.getRotationMatrix() for this calculation?
39 You are developing a hiking app that estimates the user's current altitude. Which sensor provides the most direct and energy-efficient data for calculating changes in altitude?
TYPE_GPS (via LocationManager)
TYPE_AMBIENT_TEMPERATURE
TYPE_PRESSURE (Barometer)
TYPE_ACCELEROMETER
40 An app adjusts its UI theme (e.g., light or dark mode) based on the brightness of the user's surroundings. Which sensor should it listen to for this functionality?
TYPE_LIGHT
TYPE_RELATIVE_HUMIDITY
TYPE_AMBIENT_TEMPERATURE
TYPE_PROXIMITY
41 You are designing a BLE peripheral that streams sensor data. The data packets are small (18 bytes) and must be delivered with the lowest possible latency. To minimize power consumption while meeting the latency requirement, which combination of BLE connection parameters should you request from the central device?
42
An Android app communicates with a BLE device that has a custom GATT service. To send a firmware update file (100KB), the app must write data to a characteristic. The MTU size has been negotiated to 247 bytes, allowing a payload of 244 bytes per write. The characteristic uses WRITE_TYPE_DEFAULT (Write With Response). What is the most significant performance bottleneck you must design around?
onCharacteristicWrite callback before sending the next packet.
BluetoothGatt.writeCharacteristic() call to avoid flooding the remote device.
43
You are developing an indoor navigation app that uses sensor fusion. You are using TYPE_ROTATION_VECTOR to get the device's orientation. However, you notice a slow, persistent drift in the heading (yaw/azimuth) over several minutes, even when the device is stationary. What is the most likely cause and the best way to correct it?
SENSOR_DELAY_FASTEST.
TYPE_ROTATION_VECTOR output with data from TYPE_GEOMAGNETIC_ROTATION_VECTOR which provides an absolute heading reference.
TYPE_GAME_ROTATION_VECTOR which does not use the magnetometer.
TYPE_GRAVITY instead.
44
You are using BluetoothLeScanner.startScan() with a ScanFilter to find a specific peripheral that advertises a custom service UUID. The app works on Android 11 but fails to discover any devices on Android 12, even though all runtime permissions (BLUETOOTH_SCAN, BLUETOOTH_CONNECT, ACCESS_FINE_LOCATION) are granted. The device is advertising correctly. What is a likely cause of this issue?
ScanFilter is missing a device address, which is now mandatory on Android 12.
targetSdkVersion is 31 or higher, and the PendingIntent used for the scan is missing the FLAG_IMMUTABLE or FLAG_MUTABLE flag.
BluetoothAdapter.enable() before starting the scan.
45
You're using the CompanionDeviceManager API to allow a user to configure a new headless IoT device (like a smart speaker) by connecting the phone to the device's soft AP. Which of the following statements most accurately describes a critical limitation or requirement of this process?
CompanionDeviceManager requires the user to manually select the device's Wi-Fi network from the system's Wi-Fi settings before the association can be completed.
CHANGE_WIFI_STATE permission to successfully associate with the device and cannot programmatically configure the device's final Wi-Fi credentials.
46 You are creating an augmented reality app that overlays information on the real world. You need the most stable and accurate orientation possible, but it must be immune to magnetic disturbances from nearby electronics or metal structures. Which sensor type is the most appropriate choice and why?
TYPE_GEOMAGNETIC_ROTATION_VECTOR, because it provides an absolute heading reference which is crucial for AR.
TYPE_ACCELEROMETER and TYPE_GYROSCOPE only, with a custom Kalman filter to manually fuse the data and ignore magnetic fields.
TYPE_ROTATION_VECTOR, because it fuses all available sensors for the best possible result.
TYPE_GAME_ROTATION_VECTOR, because it is specifically designed for this scenario by excluding the magnetometer data.
47
You are using the phone's barometer (TYPE_PRESSURE) to measure small changes in altitude, such as moving between floors in a building. The raw pressure reading is (in hPa or mbar) and the sea-level reference pressure is . The formula for altitude is . What is the most significant source of error you must account for in your algorithm to achieve reliable floor detection?
48 Your app needs to maintain a connection to a bonded BLE medical device. The connection must be re-established automatically and quickly if the user walks out of range and then returns. You are handling reconnection logic in a background service. Which strategy is most robust and battery-efficient for re-establishing the connection?
device.connectGatt() with autoConnect = true upon disconnection. The OS will then handle reconnection when the device is detected.
device.connectGatt() with autoConnect = false.
BluetoothLeScanner. When the device is found, stop the scan and call device.connectGatt() with autoConnect = false.
device.connectGatt() with autoConnect = false.
49
In your BluetoothGattCallback, you need to enable notifications for two different characteristics (charA and charB) immediately after connecting. Your code calls gatt.writeDescriptor() for charA's CCCD, and inside the onDescriptorWrite callback for that operation, it calls gatt.writeDescriptor() for charB's CCCD. Why is this sequential approach mandatory?
writeDescriptor twice in a row without waiting will cause a BluetoothGatt memory leak on certain Android versions.
50
You're implementing a pedometer using TYPE_STEP_COUNTER. The app is killed by the system while in the background. When the user re-opens the app hours later, how do you correctly calculate the number of steps taken during the time the app was not running?
BroadcastReceiver for a BOOT_COMPLETED intent to restart a service that continuously logs the step count to a file.
SensorManager.flush() method upon re-launch to retrieve a batch of all sensor events that occurred while the app was inactive.
51
You are building a chat application over Bluetooth Classic using RFCOMM sockets (BluetoothSocket). The app experiences random crashes with IOException: Broken pipe when sending data. The connection seems stable otherwise. The code that sends data is called from multiple UI threads. What is the most likely cause of this error?
InputStream buffer is overflowing because it cannot read data as fast as the local device is sending it.
BLUETOOTH_ADMIN permission, which is required for stable socket communication.
OutputStream of a BluetoothSocket is not thread-safe. Concurrent writes from multiple threads are corrupting the stream, leading to a connection drop.
52
In a GATT server implementation on an Android peripheral, you define a characteristic with properties PROPERTY_READ and PROPERTY_NOTIFY. You also add a Client Characteristic Configuration Descriptor (CCCD). A central device connects and writes to the CCCD to enable notifications. Later, the central disconnects and reconnects. What is the state of notifications for this central device upon reconnection?
53
You are developing an app that connects to a Wi-Fi network programmatically using ConnectivityManager.requestNetwork(). The network has no internet access (it's for an IoT device). After a successful connection, you observe that the Android OS disconnects from this network after about a minute and reconnects to the user's home Wi-Fi. How do you prevent this behavior and maintain the connection to the no-internet Wi-Fi?
WifiLock to prevent the system from managing the connection.
WifiManager API, as ConnectivityManager always prefers networks with internet.
54
Your app uses BLE scanning with ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY). On some newer Android devices, you notice the app's UI becomes sluggish and sometimes unresponsive during the scan. What is the most likely technical reason for this performance degradation?
ScanResult objects per second, causing frequent garbage collection pauses that freeze the UI thread.
SCAN_MODE_LOW_LATENCY is deprecated and causes compatibility issues with new Bluetooth controllers.
55
When using CompanionDeviceManager.associate(), what is the primary advantage of using an AssociationRequest with a BluetoothLeDeviceFilter over using the classic BluetoothAdapter.startLeScan() API for pairing with a BLE device?
BLUETOETOOTH_SCAN or ACCESS_FINE_LOCATION permissions.
startLeScan().
56 An app connects to a bonded BLE device. The device undergoes a firmware update which changes its GATT service structure (e.g., adds new characteristics). After the update, the app running on Android can no longer discover the new services or characteristics, even after reconnecting. What is the most probable cause and the correct solution?
BluetoothGatt.refresh() after service discovery. This is an unofficial, reflection-based method to force a cache clear.
57
You are trying to obtain the most accurate bearing for outdoor navigation. You get orientation data from SensorManager.getOrientation() which returns azimuth, pitch, and roll. However, the azimuth (bearing) is relative to magnetic North. To get the bearing relative to true North, what additional information do you need and how do you apply it?
GeomagneticField class, which is then added to or subtracted from the azimuth.
TYPE_GEOMAGNETIC_ROTATION_VECTOR sensor, as it automatically corrects for true North.
Eötvös effect) and calculate the deviation from true North.
58
Your app uses TYPE_LIGHT sensor to adjust screen brightness. You observe that in a consistently lit room, the sensor values fluctuate significantly (e.g., between 200 and 250 lux). To create a stable brightness setting, you decide to implement a filter. Which filtering approach is most suitable for this use case?
59
You have a BluetoothGatt connection to a peripheral. All GATT operations are initiated from a background thread to avoid blocking the UI. The BluetoothGattCallback methods, however, are invoked on a system binder thread. What is a critical threading consideration you must implement in your callback handler?
runOnUiThread to prevent ANRs.
Handler tied to your background thread's Looper to process results, ensuring that the logic that initiated the request and the logic that handles its result run on the same thread.
onCharacteristicRead, onCharacteristicWrite) to prevent them from executing concurrently.
60
You are tasked with detecting a specific, complex gesture, like drawing a figure '8' in the air. Simply using TYPE_LINEAR_ACCELERATION is insufficient as it ignores rotation. Which approach would be most effective for recognizing this gesture?
TYPE_SIGNIFICANT_MOTION sensor, which is specifically designed to trigger when complex gestures are performed.
TYPE_GYROSCOPE to track the rate of rotation on all three axes and look for a specific pattern in the angular velocities.
TYPE_ACCELEROMETER data and feed it into a machine learning model (e.g., a recurrent neural network) trained to recognize the gesture pattern.
TYPE_LINEAR_ACCELERATION data twice over time to get the device's position in 3D space and check if the path traces a figure '8'.