Posts

Showing posts from 2018

Convert a Content Provider Cursor to JSON

This is a short article where we will read the data from the content provider and convert it to JSON. So, Let's query the SMS table and get a reference to the cursor. // Query the sms table val cursor = context?.contentResolver?.query( Telephony.Sms.Inbox.CONTENT_URI, null , null , null , null ) With the cursor in hand, loop through it to read the rows and columns. cursor?.use { // Total number of columns in the table Log.v(TAG, "Column Count: ${it.columnCount}" ) // Total number of rows in the table Log.v(TAG, "Row Count: ${it.count}" ) // Move to the first item it.moveToFirst() // Temporary json variable that contains all the rows and their values val rowJson = JSONArray() // Loop through the rows do { // Temporary json variable that contains all the columns and their vales val columnJson = JSONObject() // Loop through the columns it.columnNames.forEachInde

Cronet - Chromium Network Stack for Android

Image
Cronet is a Chromium network stack used internally by Google inside its mobile apps for reliable network requests. Recently, Google made the library available for Android, IOS but the network stack has been part of Chrome web browser for a long time.  Using Cronet, the requests can be given priorities and responses can be cached in memory or on the disk. Once set the priorities, the server can decide the order to execute the requests and once cached, the future requests are fetched automatically from the cache. Cronet requests are asynchronous which means it doesn't even block the worker threads. This network stack provides support for HTTP, HTTP2, and QUIC (Quick UDP Internet Connections) protocols.  It uses   Brotli Compressed Data Format   to perform lossless compression.   Cronet automatically sets the request type to GET or POST based on the presence of the request body or the developer can always manually set the request type to their preferred choice. Le

How to Read Metadata from AndriodManifest File

Metadata tags are key-value pairs and one of the decent ways to access the API keys from the libraries. They are added to the AndroidManifest.xml under the application tag and are available through the PackageManager . If you have worked with third-party libraries or even with App shortcuts, Downloadable Fonts, Firebase MLKit, you may have come across metadata tags. In the article, let’s add the metadata tags to the app module’s Manifest file and read the metadata key-values and the key-resource from a library module both in kotlin and java. Add meta-data: Add metadata to the app module's AndroidManifest.xml file under the application tag. You can add as many metadata elements as you want and you can also add metadata under the activity, service, broadcast receiver, content provider tags. <meta-data android:name= "com.gsrikar.library.LIBRARY_ACCESS_KEY" android:value= "masndfiu4er9funwikesd" /> <meta-data and