Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 5 MCQsSmart Device Communication and Sensing Systems
What is the primary purpose of Bluetooth technology in mobile devices?
Not quite. Try another option.
Answer: Short-range wireless communication between devices
Bluetooth is a wireless technology standard used for exchanging data over short distances, typically connecting peripherals like headsets, speakers, and smartwatches to a primary device like a smartphone.
Question 2 of 60 · Bluetooth overview · Easy
In the context of Bluetooth, what does 'BLE' stand for?
Not quite. Try another option.
Answer: Bluetooth Low Energy
BLE, or Bluetooth Low Energy, is a power-conserving variant of Bluetooth designed for devices that need to run on a small battery for long periods, such as fitness trackers and IoT sensors.
Question 3 of 60 · Perform network operations · Easy
Which permission must you declare in the AndroidManifest.xml file to allow an application to create network sockets and access the internet?
Not quite. Try another option.
Answer: android.permission.INTERNET
The INTERNET permission is fundamental for any app that needs to connect to the internet to send or receive data.
Question 4 of 60 · Perform network operations · Easy
Why is it important to perform network operations on a background thread instead of the main (UI) thread in Android?
Not quite. Try another option.
Answer: To avoid blocking the user interface and causing the app to freeze
Network operations can be time-consuming. If performed on the main thread, they will block UI updates, leading to an unresponsive app and potentially an 'Application Not Responding' (ANR) error.
Question 5 of 60 · Available Devices · Easy
What is the process of searching for nearby Bluetooth devices that are broadcasting their presence called?
Not quite. Try another option.
Answer: Discovery (or Scanning)
Device discovery, also known as scanning, is the procedure used to find other Bluetooth-enabled devices in the vicinity that are discoverable.
Question 6 of 60 · Available Devices · Easy
Which method in the BluetoothAdapter class starts the process of searching for nearby Bluetooth devices?
Not quite. Try another option.
Answer: startDiscovery()
The startDiscovery() method initiates the device discovery process. It's an asynchronous call that starts scanning for devices and will notify the app via a broadcast intent when a device is found.
Question 7 of 60 · Paired Devices · Easy
What is a 'paired' or 'bonded' Bluetooth device?
Not quite. Try another option.
Answer: A device that has successfully exchanged a security key for future connections
Pairing (or bonding) creates a trusted relationship between two devices. They store a shared link key, which allows them to automatically reconnect in the future without user intervention.
Question 8 of 60 · Paired Devices · Easy
Which Android method returns a set of BluetoothDevice objects representing the devices that are already paired with the local device?
Not quite. Try another option.
Answer: getBondedDevices()
The BluetoothAdapter.getBondedDevices() method provides a set of all devices that have been previously paired with the Android device.
What is a major advantage of using Wi-Fi for companion device pairing over Bluetooth Classic?
Not quite. Try another option.
Answer: Much higher data transfer speeds
Wi-Fi offers substantially higher bandwidth than Bluetooth Classic, making it the preferred choice for applications that need to transfer large amounts of data, such as streaming high-quality video or syncing large files.
What is the purpose of the CompanionDeviceManager API in Android?
Not quite. Try another option.
Answer: To simplify the process of discovering and pairing with nearby devices
The CompanionDeviceManager provides a streamlined way for an app to manage the lifecycle of a companion device (like a smartwatch), handling scanning and pairing over Bluetooth, BLE, and Wi-Fi.
Question 11 of 60 · Connect devices · Easy
In Bluetooth communication, what is a BluetoothSocket primarily used for?
Not quite. Try another option.
Answer: To create a connection and transfer data between two devices
A BluetoothSocket is the connection point that allows an application to exchange data with another Bluetooth device via InputStream and OutputStream, much like a standard network socket.
Question 12 of 60 · Connect devices · Easy
Which communication protocol is commonly used in Android to create a reliable, stream-based connection over Bluetooth, similar to TCP?
Not quite. Try another option.
Answer: RFCOMM
RFCOMM (Radio Frequency Communication) is a Bluetooth protocol that emulates a serial port, providing a simple and reliable way to stream data between two devices.
Question 13 of 60 · Motion sensors · Easy
Which type of sensor measures the acceleration forces acting on a device, including the force of gravity?
Not quite. Try another option.
Answer: Accelerometer
An accelerometer measures the rate of change of velocity (acceleration) along the three physical axes (x, y, and z). It's used to detect orientation, screen rotation, and motion gestures like shaking.
Question 14 of 60 · Motion sensors · Easy
What does a gyroscope sensor measure?
Not quite. Try another option.
Answer: The rate of rotation around the device's axes
A gyroscope measures a device's angular velocity, or how fast it is turning. This data is crucial for advanced motion detection, such as in 360-degree photo viewers or motion-controlled games.
Question 15 of 60 · Motion sensors · Easy
To implement a feature that detects when a user 'shakes' their phone, which sensor would be most suitable to use?
Not quite. Try another option.
Answer: Accelerometer
A shake gesture involves rapid and repeated changes in acceleration. By monitoring the output from the accelerometer for high force values, an app can easily detect a shake.
Question 16 of 60 · Position sensors · Easy
Which sensor helps a device determine its orientation relative to the Earth's magnetic north, acting like a digital compass?
Not quite. Try another option.
Answer: Magnetometer
A magnetometer measures the strength and direction of the ambient magnetic field, which allows an application to determine the device's orientation relative to magnetic north.
Question 17 of 60 · Position sensors · Easy
What is the most common use case for a proximity sensor in a smartphone?
Not quite. Try another option.
Answer: Turning off the screen during a phone call when the phone is held to the ear
The proximity sensor detects when an object is close to the front of the phone. This is used to disable the touchscreen and turn off the display during a call to prevent accidental touches and conserve battery.
Question 18 of 60 · Environment sensors · Easy
Which sensor would you use to measure the ambient air pressure?
Not quite. Try another option.
Answer: Barometer
A barometer is a sensor that measures atmospheric pressure. This data can be used for weather forecasting or to estimate the device's altitude.
Question 19 of 60 · Environment sensors · Easy
A photometer, also known as a light sensor, is used to measure what?
Not quite. Try another option.
Answer: Ambient light level (illuminance)
A light sensor measures the level of ambient light in lux. It is most commonly used by the system to automatically adjust the screen's brightness.
Question 20 of 60 · Environment sensors · Easy
Which category of sensors do the thermometer, barometer, and hygrometer belong to?
Not quite. Try another option.
Answer: Environment sensors
Environment sensors are a category of hardware sensors that measure various environmental properties, such as ambient air temperature, pressure, humidity, and illumination.
Question 21 of 60 · Bluetooth overview · Medium
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?
Not quite. Try another option.
Answer: GATT (Generic Attribute Profile)
GATT is designed for Bluetooth Low Energy (BLE) and is ideal for transferring small amounts of data efficiently, which is perfect for sensor devices like heart rate monitors where power consumption is a key concern.
Question 22 of 60 · Bluetooth overview · Medium
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?
Not quite. Try another option.
Answer: The master device (smartphone)
In a Bluetooth piconet, the master device is responsible for initiating connections and synchronizing the clock for all slave devices connected to it.
Question 23 of 60 · Perform network operations · Medium
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?
Not quite. Try another option.
Answer: socket.connect()
The connect() method is a blocking call as it waits for the connection to be established or fail. Performing this on the main thread will freeze the UI, leading to an ANR error. It must be run in a background thread.
Question 24 of 60 · Perform network operations · Medium
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?
Not quite. Try another option.
Answer: A continuous loop reading from the InputStream within a background thread
Reading from an InputStream is a blocking operation. To continuously receive data without blocking the rest of the application, you must implement a loop in a background thread (e.g., using Thread or a coroutine) that constantly listens for and processes incoming bytes.
Question 25 of 60 · Perform network operations · Medium
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?
The listenUsingRfcommWithServiceRecord method creates a listening RFCOMM socket that requires authentication and encryption, making it the secure option for a server socket. The insecure version is for connections that don't require pairing encryption.
Question 26 of 60 · Available Devices · Medium
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?
Not quite. Try another option.
Answer: Use a Handler to stop the scan after a predefined period (e.g., 10-15 seconds)
Device discovery is a power-intensive operation. It is a best practice to set a time limit for the scan and stop it programmatically using a Handler or similar mechanism to conserve battery life.
Question 27 of 60 · Available Devices · Medium
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?
Not quite. Try another option.
Answer: Use a ScanFilter with the required ServiceUuid and pass it to startScan()
ScanFilter allows you to perform hardware-level filtering of advertising packets. By specifying a service UUID in the filter, the Bluetooth controller will only notify your app about devices that advertise that specific service, which is much more efficient than filtering in the app code.
Question 28 of 60 · Paired Devices · Medium
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?
Not quite. Try another option.
Answer: By calling bluetoothAdapter.getBondedDevices()
The getBondedDevices() method returns a Set<BluetoothDevice> containing all devices that are currently paired (bonded) with the local adapter. This is a direct, non-blocking call that does not involve any scanning.
Question 29 of 60 · Paired Devices · Medium
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?
Not quite. Try another option.
Answer: BluetoothDevice.ACTION_BOND_STATE_CHANGED
The ACTION_BOND_STATE_CHANGED broadcast is sent whenever the pairing state of a remote device changes. An app can register a BroadcastReceiver for this action to be notified when a device becomes BOND_BONDED, BOND_BONDING, or BOND_NONE.
Question 30 of 60 · Wi-Fi Companion device pairing overview · Medium
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?
Not quite. Try another option.
Answer: It grants the app special privileges, like running in the background and accessing notifications, without requiring the user to grant them manually in settings
The Companion Device Manager streamlines the user experience. By having the user pair the device through this system-managed flow, the companion app is granted a set of powerful capabilities (like background services and notification access) that would otherwise require separate, explicit user permission.
Question 31 of 60 · Wi-Fi Companion device pairing overview · Medium
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?
Not quite. Try another option.
Answer: A DeviceFilter specifying characteristics like a service UUID or device name pattern
The AssociationRequest is configured with a DeviceFilter (e.g., BluetoothDeviceFilter or WifiDeviceFilter). This filter tells the system what kinds of devices to look for and display to the user, ensuring only relevant companion devices are shown in the pairing dialog.
Question 32 of 60 · Connect devices · Medium
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?
Not quite. Try another option.
Answer: NET_CAPABILITY_VALIDATED
NET_CAPABILITY_VALIDATED indicates that the network provides verified internet access. For device-to-device communication over Wi-Fi where internet isn't available or required, you must not include this capability. The system would otherwise disconnect from the network after failing its internet connectivity check.
Question 33 of 60 · Connect devices · Medium
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?
Not quite. Try another option.
Answer: One device creates a ServerSocket and the other creates a Socket using the Network object obtained from the Wi-Fi Aware session
Wi-Fi Aware is for discovery and session setup. Once a Network path is established, you use standard networking sockets (ServerSocket and Socket) bound to that specific network to create a direct data link, similar to a regular TCP/IP connection.
Question 34 of 60 · Motion sensors · Medium
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?
Not quite. Try another option.
Answer: TYPE_ROTATION_VECTOR
TYPE_ROTATION_VECTOR is a software-based (fused) sensor that combines data from the accelerometer, gyroscope, and magnetometer. It provides a stable and accurate representation of the device's orientation as a quaternion or rotation vector, which is ideal for tracking orientation without the drift associated with gyroscopes alone.
Question 35 of 60 · Motion sensors · Medium
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?
Not quite. Try another option.
Answer: Calculating the magnitude of the linear acceleration vector () and checking if it exceeds a high threshold
A shake is characterized by rapid acceleration and deceleration. By calculating the magnitude of the acceleration vector (after removing gravity), you can detect this spike. If the calculated magnitude surpasses a certain threshold, it indicates a shake event.
Question 36 of 60 · Motion sensors · Medium
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?
Not quite. Try another option.
Answer: A low-pass filter to average out noise and sudden jerks
A low-pass filter smooths out the data by averaging current readings with previous ones. This effectively removes high-frequency noise (jitter) and provides a more stable reading for tilt-based controls. A common simple implementation is an exponential moving average.
Question 37 of 60 · Position sensors · Medium
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?
Not quite. Try another option.
Answer: TYPE_MAGNETIC_FIELD
The TYPE_MAGNETIC_FIELD sensor provides the raw data for the ambient geomagnetic field strength along the x, y, and z axes. This data, often used in conjunction with the accelerometer, is essential for calculating the device's bearing (compass heading).
Question 38 of 60 · Position sensors · Medium
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?
Not quite. Try another option.
Answer: Accelerometer and Magnetic Field sensor
SensorManager.getRotationMatrix() computes the device's rotation matrix based on two reference vectors: the direction of gravity (from the accelerometer) and the direction of the Earth's magnetic field (from the magnetometer). These two vectors define a fixed coordinate system relative to the Earth.
Question 39 of 60 · Environment sensors · Medium
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?
Not quite. Try another option.
Answer: TYPE_PRESSURE (Barometer)
The atmospheric pressure sensor (barometer) is highly effective for measuring relative altitude changes. As altitude increases, atmospheric pressure decreases in a predictable way. This method is often more responsive and power-efficient for tracking elevation gain/loss than relying solely on GPS.
Question 40 of 60 · Environment sensors · Medium
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?
Not quite. Try another option.
Answer: TYPE_LIGHT
The TYPE_LIGHT sensor measures the ambient light level in lux (lx). This is the designated sensor for determining how bright the device's environment is, making it perfect for features like automatic screen brightness adjustment or dynamic UI theming.
Question 41 of 60 · Bluetooth overview · Hard
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?
Not quite. Try another option.
Answer: A short Connection Interval, zero Slave Latency, short Supervision Timeout.
For lowest latency, the Connection Interval (the time between connection events) must be as short as possible. Slave Latency allows the peripheral to skip connection events to save power, which is counterproductive for low-latency streaming, so it should be zero. A short Supervision Timeout allows for faster detection of a lost connection, which is often desirable in low-latency applications.
Question 42 of 60 · Perform network operations · Hard
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?
Not quite. Try another option.
Answer: The round-trip time (RTT) for each write operation, as the app must wait for the onCharacteristicWrite callback before sending the next packet.
With WRITE_TYPE_DEFAULT, each write is acknowledged. The Android Bluetooth stack enforces a sequential, one-at-a-time transaction model. The app sends a packet, waits for the peripheral's ACK, and receives the onCharacteristicWrite callback. Only then can it send the next packet. This RTT dominates the transfer time, not the PHY rate or local processing.
Question 43 of 60 · Motion sensors · Hard
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?
Not quite. Try another option.
Answer: The gyroscope has an inherent bias (drift). The solution is to fuse the TYPE_ROTATION_VECTOR output with data from TYPE_GEOMAGNETIC_ROTATION_VECTOR which provides an absolute heading reference.
TYPE_ROTATION_VECTOR is a fused sensor that primarily relies on the gyroscope for high-frequency orientation changes, but gyroscopes inherently drift over time. While it uses the magnetometer for correction, this correction can be slow. TYPE_GEOMAGNETIC_ROTATION_VECTOR provides an absolute (magnetic North) reference without using the gyroscope. Fusing these two can correct for the gyroscopic drift while maintaining responsiveness.
Question 44 of 60 · Available Devices · Hard
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?
Not quite. Try another option.
Answer: The app's targetSdkVersion is 31 or higher, and the PendingIntent used for the scan is missing the FLAG_IMMUTABLE or FLAG_MUTABLE flag.
Starting with Android 12 (API 31), apps must explicitly specify the mutability of PendingIntent objects. The BluetoothLeScanner API uses PendingIntents for batch scanning or for scans initiated via a callback intent. A missing flag will cause the startScan call to fail silently or throw a security exception, which is a common and difficult-to-debug issue when migrating apps to newer Android versions.
Question 45 of 60 · Wi-Fi Companion device pairing overview · Hard
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?
Not quite. Try another option.
Answer: For the association to succeed without requiring location services to be enabled, the device's Wi-Fi AP must have a specific prefix (e.g., 'DIRECT-') or suffix in its SSID.
A key feature and requirement of CompanionDeviceManager for Wi-Fi devices is that to bypass the ACCESS_FINE_LOCATION permission requirement, the target Wi-Fi network's SSID must conform to a specific pattern. This tells the system that the scan is for device setup, not location tracking. If the SSID is arbitrary, the user must have location services enabled for the scan to find the network.
Question 46 of 60 · Position sensors · Hard
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?
Not quite. Try another option.
Answer: TYPE_GAME_ROTATION_VECTOR, because it is specifically designed for this scenario by excluding the magnetometer data.
TYPE_GAME_ROTATION_VECTOR is a virtual sensor that provides orientation data without using the magnetometer. It fuses data from the accelerometer and gyroscope. This makes it ideal for environments with magnetic interference. While it will drift over time regarding absolute heading (yaw), it provides a very stable and responsive local orientation, which is often sufficient for AR and is far superior to the magnetometer-based sensors in magnetically noisy areas.
Question 47 of 60 · Environment sensors · Hard
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?
Not quite. Try another option.
Answer: Changes in local weather patterns, which can alter the ambient air pressure by several hPa over a short time, mimicking a change in altitude.
While sensor noise and the accuracy of are factors, the most significant and dynamic source of error is weather. A change in atmospheric pressure (e.g., an approaching storm) can cause the calculated altitude to drift by tens of meters, which is far greater than the few meters between floors. A robust algorithm must differentiate between altitude changes (fast pressure changes) and weather changes (slow pressure changes) or use a secondary reference.
Question 48 of 60 · Paired Devices · Hard
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?
Not quite. Try another option.
Answer: Implement a scanner with an exponential backoff strategy. Start with a short scan interval, and if the device isn't found, double the wait time before the next scan, up to a maximum limit, then call device.connectGatt() with autoConnect = false.
autoConnect=true is slow and unreliable for quick reconnections. An aggressive continuous scan drains the battery. A simple periodic scan is better but can still be inefficient. The exponential backoff strategy provides the best balance: it attempts to reconnect quickly at first, but if the device remains out of range, it reduces scanning frequency to conserve significant battery power, while still ensuring an eventual reconnection.
Question 49 of 60 · Connect devices · Hard
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?
Not quite. Try another option.
Answer: The Android BLE stack is asynchronous but serial; it can only handle one GATT operation at a time. Starting a new operation before the previous one's callback is received will cause the second operation to fail.
A critical aspect of Android's BLE API is that all GATT operations (read, write, descriptor write) are asynchronous but must be executed serially. You must wait for the corresponding callback (e.g., onDescriptorWrite, onCharacteristicWrite) for the current operation to complete before initiating the next one. Attempting to issue commands in parallel will result in all but the first command being dropped or failing with an error.
Question 50 of 60 · Motion sensors · Hard
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?
Not quite. Try another option.
Answer: On the first sensor event after re-launch, the event's value will be the total count since the last device reboot. You must subtract a previously stored value to find the delta.
The TYPE_STEP_COUNTER is a hardware-backed counter that maintains its value across app restarts and even while the app is not running. It only resets on a device reboot. The correct implementation is to store the last known step count in persistent storage (e.g., SharedPreferences). When the app restarts, you get the new total count from the first sensor event and subtract the stored value to get the number of steps taken in the interim.
Question 51 of 60 · Perform network operations · Hard
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?
Not quite. Try another option.
Answer: The OutputStream of a BluetoothSocket is not thread-safe. Concurrent writes from multiple threads are corrupting the stream, leading to a connection drop.
The InputStream and OutputStream objects obtained from a BluetoothSocket are not guaranteed to be thread-safe. If multiple threads attempt to call outputStream.write() concurrently, the underlying data stream can be corrupted, leading to protocol errors and the remote side closing the connection, which manifests as a Broken pipeIOException on the writing side. All writes must be synchronized or performed from a single, dedicated writer thread.
Question 52 of 60 · Bluetooth overview · Hard
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?
Not quite. Try another option.
Answer: Notifications are automatically re-enabled because the central is a bonded device and the GATT server remembers its CCCD configuration.
The Android Bluetooth stack, when acting as a GATT server, automatically persists the CCCD values for bonded devices. When a bonded central reconnects, the server remembers its previous subscription state and will start sending notifications automatically without requiring the central to write to the CCCD again. This is a crucial feature for creating seamless user experiences with BLE devices.
Question 53 of 60 · Connect devices · Hard
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?
Not quite. Try another option.
Answer: When the system prompts the user if they want to stay connected to the network without internet, the app must instruct the user to accept. Programmatically, you can't prevent this initial check.
This is a standard Android behavior. When the OS detects that a Wi-Fi network has no internet connectivity (a "captive portal" or isolated network), it may switch back to a network that does (like cellular or another Wi-Fi). It presents a system dialog or notification to the user asking for confirmation to stay on the no-internet network. The app cannot bypass this user-facing validation step. Once the user confirms, the OS will maintain the connection as long as the app holds the network request.
Question 54 of 60 · Available Devices · Hard
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?
Not quite. Try another option.
Answer: This scan mode creates a large number of ScanResult objects per second, causing frequent garbage collection pauses that freeze the UI thread.
While the scan itself runs in a binder thread, the results are delivered back to your app. SCAN_MODE_LOW_LATENCY can deliver a very high volume of advertising packets, including duplicates. If your onScanResult or onBatchScanResults callback allocates new objects for each result without careful management, it can trigger the Garbage Collector (GC) very frequently. These GC pauses, especially on older or less powerful devices, can be long enough to cause skipped frames or freezes on the main UI thread.
Question 55 of 60 · Wi-Fi Companion device pairing overview · Hard
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?
Not quite. Try another option.
Answer: It presents a system-managed UI for device selection, and upon user confirmation, grants the app a long-term capability to interact with that device without needing to scan again in the future.
The key benefit of the Companion Device Manager is not just about permissions during the initial scan. After the user pairs a device through the system-provided dialog, the system grants the app a persistent association. The app can then wake up when the device is nearby and interact with it without needing to hold runtime scan permissions, which is a significant power and privacy advantage for long-term device management.
Question 56 of 60 · Paired Devices · Hard
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?
Not quite. Try another option.
Answer: The Android OS has cached the device's GATT services from the initial bonding. The solution is to programmatically un-bond and re-bond with the device.
Android aggressively caches the GATT services of bonded (paired) devices to speed up future connections. If the peripheral's service structure changes, this cache becomes stale and prevents the discovery of new attributes. The official and most reliable way to solve this is to remove the bond (either from system settings or programmatically if possible, though this is difficult) and then re-initiate the bonding process. The undocumented refresh() method is notoriously unreliable across different devices and Android versions.
Question 57 of 60 · Position sensors · Hard
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?
Not quite. Try another option.
Answer: You need the device's current GPS location to calculate the magnetic declination using the GeomagneticField class, which is then added to or subtracted from the azimuth.
Magnetic North and true North are not the same, and the difference between them (magnetic declination) varies depending on your location on Earth and time. The GeomagneticField class in the Android SDK is designed for this purpose. You provide it with the device's latitude, longitude, altitude, and the current time, and it returns the declination angle. You then add this declination value to your magnetic azimuth to get the true North azimuth.
Question 58 of 60 · Environment sensors · Hard
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?
Not quite. Try another option.
Answer: A low-pass filter (e.g., an exponential moving average), which smooths out high-frequency noise while still responding to genuine changes in brightness.
A low-pass filter is ideal for smoothing sensor data. An exponential moving average (EMA) is a particularly efficient implementation. The formula is filtered_value = \alpha * new_value + (1 - \alpha) * last_filtered_value. It effectively dampens the rapid, small fluctuations (noise) from the light sensor while allowing the filtered value to gradually track slower, real changes in ambient light. It's computationally cheap and doesn't require a large data buffer.
Question 59 of 60 · Perform network operations · Hard
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?
Not quite. Try another option.
Answer: The callback handler should use a 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.
While it's important not to block the binder thread, simply dispatching to the main thread isn't always correct, especially for data processing. The best practice is to manage a dedicated background thread with a Looper for all BLE logic. Requests are posted to this thread's Handler. The results from the BluetoothGattCallback (on a binder thread) are then posted back to the same Handler. This serializes all BLE operations and results on a single thread, preventing complex synchronization issues and keeping the UI thread free.
Question 60 of 60 · Motion sensors · Hard
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?
Not quite. Try another option.
Answer: Record a time-series of raw TYPE_ACCELEROMETER data and feed it into a machine learning model (e.g., a recurrent neural network) trained to recognize the gesture pattern.
Complex gestures involve a unique signature of both linear and rotational movements. Double integration of acceleration is extremely prone to drift and error, making it impractical. TYPE_GYROSCOPE alone misses translational movement. TYPE_SIGNIFICANT_MOTION is for coarse detection of user movement (e.g., walking vs. still), not specific gestures. The most robust and modern approach is to treat it as a time-series classification problem, using ML to learn the complex spatio-temporal patterns from raw sensor data (accelerometer, and often gyroscope as well).
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of CSE227 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of CSE227 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.