<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Niveditha Kabbur on Medium]]></title>
        <description><![CDATA[Stories by Niveditha Kabbur on Medium]]></description>
        <link>https://medium.com/@nivedithagemini?source=rss-d5d89c67ada3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bgbBvcG6PPcj07Nod9HsZw.jpeg</url>
            <title>Stories by Niveditha Kabbur on Medium</title>
            <link>https://medium.com/@nivedithagemini?source=rss-d5d89c67ada3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:21:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nivedithagemini/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Handling Background Execution Limits: Android Oreo]]></title>
            <link>https://medium.com/@nivedithagemini/handling-background-execution-limits-android-oreo-cdb7c071e6a2?source=rss-d5d89c67ada3------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdb7c071e6a2</guid>
            <category><![CDATA[background-task]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jobintentservice]]></category>
            <category><![CDATA[android-oreo]]></category>
            <dc:creator><![CDATA[Niveditha Kabbur]]></dc:creator>
            <pubDate>Thu, 19 Apr 2018 07:04:25 GMT</pubDate>
            <atom:updated>2018-04-19T07:04:25.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever an app runs in the background, it consumes some of the device’s limited resources, like RAM. This can result in an impaired user experience, especially if the user is using a resource-intensive app, such as playing a game or watching video. To improve the user experience, Android 8.0 (API level 26) imposes limitations on what apps can do while running in the background.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_KAc8TqtAvQww7QF06p3Q.jpeg" /></figure><h3><strong>Overview:</strong></h3><p>Many Android apps and services can be running simultaneously. For example, a user could be playing a game in one window while browsing the web in another window, and using a third app to play music. The more apps are running at once, the more load is placed on the system. If additional apps or services are running in the background, this places additional loads on the system, which could result in a poor user experience; for example, the music app might be suddenly shut down.</p><p>To lower the chance of these problems, Android 8.0 places limitations on what apps can do while users aren’t directly interacting with them. Apps are restricted in two ways:</p><h3><strong>1. Broadcast Limitations:</strong></h3><p>With limited exceptions, apps cannot use their manifest to register for implicit broadcasts. They can still register for these broadcasts at run-time, and they can use the manifest to register for explicit broadcasts targeted specifically at their app.</p><p><strong>Example: </strong>Registering implicit broadcast receiver for network change.</p><h3><strong>Below Oreo:</strong></h3><p>Register the receiver in the Android manifest file.</p><pre>&lt;receiver<br>            android:name=&quot;.NetworkChangeBoradcastReceiver&quot;<br>            android:enabled=&quot;true&quot;&gt;<br>            &lt;intent-filter&gt;<br>                &lt;action android:name=&quot;android.net.conn.CONNECTIVITY_CHANGE&quot; /&gt;<br>            &lt;/intent-filter&gt;<br>        &lt;/receiver&gt;</pre><h3>Oreo or higher:</h3><p>Register the receiver in the application itself using <a href="https://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter)">Context.registerReceiver()</a> .</p><pre><em>//Register receiver for network change<br></em>BroadcastReceiver br = <strong>new </strong>NetworkChangeBroadcastReceiver();<br>IntentFilter filter = <strong>new </strong>IntentFilter(<strong><em>CONNECTIVITY_ACTION</em></strong>);<br>getApplicationContext().registerReceiver(br, filter);</pre><h3>2.<strong> Background Service Limitations:</strong></h3><p>Services running in the background can consume device resources, potentially resulting in a worse user experience. To overcome this problem, android Oreo has added several restrictions by distinguishing between <em>foreground</em> and <em>background</em> apps.</p><p>To know more about the restrictions in details please refer the link below: <a href="https://developer.android.com/about/versions/oreo/background.html#services">https://developer.android.com/about/versions/oreo/background.html#services</a></p><p>How to change different services for targeting Oreo devices:</p><p><strong>a) Bound services are not affected:</strong> These restrictions do not affect bound services in any way. If your app defines a bound service, other components can bind to that service whether or not your app is in the foreground.</p><p><strong>b) IntentService is affected:</strong><a href="https://developer.android.com/reference/android/app/IntentService.html">IntentService</a> is a service, and is therefore subject to the new restrictions on background services. As a result, many apps that rely on <a href="https://developer.android.com/reference/android/app/IntentService.html">IntentService</a> do not work properly when targeting Android 8.0 or higher. For this reason, <a href="https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0">Android Support Library 26.0.0</a> introduces a new<a href="https://developer.android.com/reference/android/support/v4/app/JobIntentService.html">JobIntentService</a> class, which provides the same functionality as <a href="https://developer.android.com/reference/android/app/IntentService.html">IntentService</a> but uses jobs instead of services when running on Android 8.0 or higher.</p><p>Example:</p><h3>Below Oreo:</h3><p>Using IntentService.</p><p>Add the service in the Manifest file:</p><pre>&lt;<strong>service<br>    android:name=&quot;.service.ExampleService&quot;<br>    android:exported=&quot;false&quot;</strong>/&gt;</pre><p>Create a class that extends IntentService and handle the background task in the onHandleIntent() method.</p><pre><strong>public class </strong>ExampleService <strong>extends </strong>IntentService {<br><br>    <em>// Must create a default constructor<br>    </em><strong>public </strong>ExampleService() {<br>        <strong>super</strong>(<strong>&quot;example-service&quot;</strong>);<br>    }<br>    <br>    @Override<br>    <strong>protected void </strong>onHandleIntent(@Nullable Intent intent) {<br>        <em>// This describes what will happen when service is triggered<br>    </em>}<br>}</pre><p>Call the service from another android component.</p><pre><em>Intent intent = new Intent(context, ExampleService.class);<br>// Start the service<br> context.startService(intent);</em></pre><h3>Oreo or higher:</h3><p>Using JobIntentService.</p><p>Add the service in the Manifest file:</p><pre>&lt;<strong>service android:name=&quot;.service.ExampleJobIntentService&quot;<br>    android:permission=&quot;android.permission.BIND_JOB_SERVICE&quot;<br>    android:exported=&quot;true&quot;<br>    </strong>/&gt;</pre><p>Declare the WAKE_LOCK permission in the Manifest file:</p><pre>&lt;<strong>uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; </strong>/&gt;</pre><p>Create a class that extends JobIntentService and handle the background task in the onHandleWork() method.</p><pre><strong>public class ExampleJobIntentService extends </strong>JobIntentService {<br>   <em><br>    </em><strong>static final int <em>JOB_ID </em></strong>= 1000; <em>//Unique job ID.</em><br>   <em><br>     //Convenience method for enqueuing work in to this service.<br>    <br>    </em><strong>public static void </strong>enqueueWork(Context context, Intent work) {<br>        <em>enqueueWork</em>(context, ExampleJobIntentService.<strong>class</strong>, <strong><em>JOB_ID</em></strong>, work);<br>    }<br>    <br>    @Override<br>    <strong>protected void </strong>onHandleWork(@NonNull Intent intent) {<br>         <em>// This describes what will happen when service is triggered</em><br>    }<br>}</pre><p>Call the service from another android component.</p><pre><em>// JobIntentService for background task<br></em>Intent i = <strong>new </strong>Intent(context, ExampleJobIntentService.<strong>class</strong>);<br>ExampleJobIntentService.<em>enqueueWork</em>(context,i);</pre><p>Hope this is helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdb7c071e6a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android BLE Overview]]></title>
            <link>https://medium.com/@nivedithagemini/android-ble-overview-ee8cc0c9175d?source=rss-d5d89c67ada3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee8cc0c9175d</guid>
            <category><![CDATA[ble]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <dc:creator><![CDATA[Niveditha Kabbur]]></dc:creator>
            <pubDate>Wed, 23 Aug 2017 11:27:13 GMT</pubDate>
            <atom:updated>2017-08-23T11:27:13.446Z</atom:updated>
            <content:encoded><![CDATA[<p>Bluetooth LE provides data transfers with low power consumption, making it possible to equip all types of sports and fitness equipment with wireless connectivity. Today, Bluetooth solutions span from basic fitness tracking to sophisticated devices that help fine tune the performance of professional athletes.</p><p>BLE is used in Bluetooth Mesh Networking, one of the technologies to implement Internet of Things (IoT).</p><p><strong>Bluetooth Low Energy in Android:</strong> Android 4.3 introduces built-in platform support for Bluetooth Low Energy (BLE) in the <em>central role</em> and provides APIs that apps can use to discover devices, query for services, and transmit information.</p><p>BLE Central Role: The device in the central role scans, looking for advertisement.</p><p>BLE Peripheral Role: The device in the peripheral role makes the advertisement.</p><p><strong>The android BLE permissions:</strong></p><p>In order to use Bluetooth features in the application, the Bluetooth permission <a href="https://developer.android.com/reference/android/Manifest.permission.html#BLUETOOTH">BLUETOOTH</a> is required. It is needed to perform any Bluetooth communication, such as requesting a connection, accepting a connection, and transferring data.</p><p>The permissions has to be declared in the Android Manifest file.</p><pre>&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADMIN&quot;/&gt;</pre><p>Before starting the application, it is required to check if the device supports BLE, based on which the BLE related features can be disabled or enabled.</p><pre>// Use this check to determine whether BLE is supported on the device. Then<br>// you can selectively disable BLE-related features.<br>if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {<br>    Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();<br>    finish();<br>}</pre><p><strong>Requesting Location Permissions for API 23+</strong></p><p>The BLE requires the android location permissions because LE Beacons are often associated with location and without these permissions, scans won’t return any results.</p><p>Add the below code in the AndroidManifest.xml file.</p><pre>&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;</pre><p>Request permission to access the location.</p><pre>if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) { <br>      requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);<br>}</pre><p><strong>Setting up the BLE of the android Device:</strong></p><p><strong>1)</strong> <strong>Get the Bluetooth Adapter:</strong></p><p>The BluetoothAdapter is required for any and all Bluetooth activity. The BluetoothAdapter represents the device’s own Bluetooth adapter (the Bluetooth radio). There’s one Bluetooth adapter for the entire system, and the android application can interact with it using this object. The snippet below shows how to get the adapter.</p><pre>private BluetoothAdapter mBluetoothAdapter;<br>...<br>// Initializes Bluetooth adapter.<br>final BluetoothManager bluetoothManager =<br>        (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);<br>mBluetoothAdapter = bluetoothManager.getAdapter();</pre><p><strong>2)</strong> <strong>Enable Bluetooth:</strong></p><p>The following snippet checks whether Bluetooth is enabled. If it isn’t, the snippet displays an error prompting the user to go to Settings to enable Bluetooth.</p><pre>// Ensures Bluetooth is available on the device and it is enabled. If not,<br>// displays a dialog requesting user permission to enable Bluetooth.<br>if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {<br>    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);<br>    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);<br>}</pre><p><strong>Scanning for BLE devices:</strong></p><p>To start the scanning for BLE devices, the startLeScan() method is used. And to stop the scanning, the stopLeScan() method is used.</p><pre>mBluetoothAdapter.startLeScan(mLeScanCallback); // To start the LE scan.</pre><pre>mBluetoothAdapter.stopLeScan(mLeScanCallback); // To stop the LE scan.</pre><p>Both the methods take <a href="https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html">BluetoothAdapter.LeScanCallback</a> as the parameter. This callback must be implemented, because that is how scan results are returned.</p><p>The implementation of the <a href="https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html">BluetoothAdapter.LeScanCallback</a>, which is the interface used to deliver BLE scan results is as below:</p><pre>// Device scan callback.<br>private BluetoothAdapter.LeScanCallback mLeScanCallback =<br>        new BluetoothAdapter.LeScanCallback() {<br>    @Override<br>    public void onLeScan(final BluetoothDevice device, int rssi,<br>            byte[] scanRecord) {<br>        runOnUiThread(new Runnable() {<br>           @Override<br>           public void run() {<br>               // Add your code here<br>           }<br>       });<br>   }<br>};</pre><p><strong>Connecting to a GATT server:</strong></p><p>The first step in interacting with a BLE device is connecting to it — more specifically, connecting to the GATT server on the device. To connect to a GATT server on a BLE device, the <a href="https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt%28android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback%29">connectGatt()</a> method is used. This method takes three parameters: a <a href="https://developer.android.com/reference/android/content/Context.html">Context</a> object, autoConnect (boolean indicating whether to automatically connect to the BLE device as soon as it becomes available), and a reference to a <a href="https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html">BluetoothGattCallback</a>.</p><pre>mBluetoothGatt = device.connectGatt(this, false, mGattCallback);</pre><p>The BluetoothGattCallback, provides various methods to get that information about the BLE devices.</p><pre>// Various callback methods defined by the BLE API.<br>    private final BluetoothGattCallback mGattCallback =<br>            new BluetoothGattCallback() {<br>        @Override<br>        public void onConnectionStateChange(BluetoothGatt gatt, int status,<br>                int newState) {<br>           <br> ...<br>        }</pre><pre>        @Override<br>        // New services discovered<br>        public void onServicesDiscovered(BluetoothGatt gatt, int status) {<br>            if (status == BluetoothGatt.GATT_SUCCESS) {<br>              ...<br>            } else {<br>                Log.w(TAG, &quot;onServicesDiscovered received: &quot; + status);<br>            }<br>        }</pre><pre>        @Override<br>        // Result of a characteristic read operation<br>        public void onCharacteristicRead(BluetoothGatt gatt,<br>                BluetoothGattCharacteristic characteristic,<br>                int status) {<br>            if (status == BluetoothGatt.GATT_SUCCESS) {<br>               ...<br>            }<br>        }<br>     ...<br>    };</pre><p><strong>Reading BLE Attributes:</strong></p><p>Key BLE terms and concepts:</p><p><strong>1) Generic Attribute Profile (GATT)</strong> — The GATT profile is a general specification for sending and receiving short pieces of data known as “attributes” over a BLE link. All current Low Energy application profiles are based on GATT.</p><p><strong>2)</strong> <strong>Attribute Protocol (ATT)</strong> — GATT is built on top of the Attribute Protocol (ATT). ATT is optimized to run on BLE devices. Each attribute is uniquely identified by a Universally Unique Identifier (UUID), which is a standardized 128-bit format for a string ID used to uniquely identify information. The <em>attributes</em> transported by ATT are formatted as <em>characteristics</em> and <em>services</em>.</p><p><strong>3) Service</strong> — A service is a collection of characteristics. For example, you could have a service called “Heart Rate Monitor” that includes characteristics such as “heart rate measurement.” A list of existing GATT-based profiles and services can be found on <a href="https://www.bluetooth.org/en-us/specification/adopted-specifications">bluetooth.org</a>.</p><p><strong>4) Characteristic</strong> — A characteristic contains a single value and 0-n descriptors that describe the characteristic’s value. A characteristic can be thought of as a type, analogous to a class.</p><p><strong>5) Descriptor</strong> — Descriptors are defined attributes that describe a characteristic value.</p><p>Once the Android app has connected to a GATT server and discovered services, it can read and write attributes, where supported.</p><p>There are different methods to obtain the services and the characteristics.</p><p>The gatt.discoverServices() is used to find all the services provided. It can be obtained in the onServicesDiscovered() method of the BluetoothGattCallback.</p><p>The getServices() method is used to to obtain the services and the getCharacteristics() method is used to get the characteristics.</p><p>The mBluetoothGatt.readCharacteristic() method is used to read the Characteristics.</p><p>The various methods provided by the BluetoothGattService can be found at <a href="https://developer.android.com/reference/android/bluetooth/BluetoothGattService.html">https://developer.android.com/reference/android/bluetooth/BluetoothGattService.html</a></p><p>The various methods provided by the BluetoothGattCharacteristic can be found at <a href="https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html">https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html</a></p><p>More information on Gatt can be found at <a href="https://www.bluetooth.com/specifications/gatt">https://www.bluetooth.com/specifications/gatt</a></p><p>Sample code can be found at <a href="https://github.com/googlesamples/android-BluetoothLeGatt">https://github.com/googlesamples/android-BluetoothLeGatt</a></p><p>Hope this is helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee8cc0c9175d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>