<?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 Nikit Bhandari on Medium]]></title>
        <description><![CDATA[Stories by Nikit Bhandari on Medium]]></description>
        <link>https://medium.com/@nikitbhandari?source=rss-1c3fe5ef9e81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HJVPBP4xwuL6WIPoXYG13Q.png</url>
            <title>Stories by Nikit Bhandari on Medium</title>
            <link>https://medium.com/@nikitbhandari?source=rss-1c3fe5ef9e81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:02:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikitbhandari/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[Exploring Photo Picker in Android 13]]></title>
            <link>https://proandroiddev.com/exploring-photo-picker-in-android-13-3823d78007a9?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/3823d78007a9</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Mon, 14 Feb 2022 14:45:45 GMT</pubDate>
            <atom:updated>2022-02-14T14:45:45.710Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*IY98A6VSCLqhb5mb" /><figcaption>Image credits: <a href="https://developer.android.com/">https://developer.android.com/</a></figcaption></figure><p>Google recently announced the first Developer Preview of Android 13, while there are a lot of new APIs, the Photo picker excited me a lot both as a user and a developer.</p><p>If you want to try the Android 13 APIs, you can follow the instructions mentioned in the <a href="https://developer.android.com/about/versions/13/setup-sdk">documentation</a>. Although if you follow the documentation word by word you will not be able to compile the project, the documentation recommends adding the following code snippet in your build.gradle to set up the SDK.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ab7fc268b0fa4b310ecd105b33bd4c7/href">https://medium.com/media/1ab7fc268b0fa4b310ecd105b33bd4c7/href</a></iframe><p>But at the time of writing this article, you will get the following error:</p><pre>Unsupported value: Tiramisu. Format must be one of:<br>- android-31<br>- android-31-ext2<br>- android-T<br>- vendorName:addonName:31</pre><p>The fix is to use compileSdkPreview and targetSdkPreview instead like it is done in the code snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98825d6ae0c78102d71316ed5d9dad0c/href">https://medium.com/media/98825d6ae0c78102d71316ed5d9dad0c/href</a></iframe><p>Now you should be able to work with the Android 13 SDK 😃</p><h4>What’s a Photo picker?</h4><p>Photo picker provides you a new way to select media files stored in your device and cloud using an intent.</p><p>You may be thinking, isn’t there already an intent to open the Gallery? Yes, the Photo picker is similar to that in terms of functionality and it comes with a new refreshed UI.</p><p>Let’s have a look at the existing way of opening a Gallery through an intent</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/477bd6caed8b4908c049572dda49fdf1/href">https://medium.com/media/477bd6caed8b4908c049572dda49fdf1/href</a></iframe><p>The following GIF shows how this intent would open up your Gallery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eW5yj2e1x1QT8PfelTSiiw.gif" /></figure><p>Now let’s see how to use the Photo picker in Android 13</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7316aedf8688a9d06802dbd666847bc7/href">https://medium.com/media/7316aedf8688a9d06802dbd666847bc7/href</a></iframe><p>This code snippet would open up a dialog from the bottom and allow the user to select an image from the Gallery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Vgjle8M1QYRwcjIgoufPw.gif" /></figure><p>If you want to select multiple images you can provide the maximum number of images using EXTRA_PICK_IMAGES_MAX extra</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62461d2c1400f0fc08a3d22ba1a1629b/href">https://medium.com/media/62461d2c1400f0fc08a3d22ba1a1629b/href</a></iframe><p>The maximum value that we are using in the above code snippet can be any positive integer greater than 1 and less than or equal to the value returned from MediaStore.getPickImagesMaxLimit()</p><p>Now the dialog would open up in full screen and you also have the option to view the selected images in a preview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WePc_CdF30QQuLiXiOMy8w.gif" /></figure><p>You can also provide the media type, in case you want the user to select only videos or images</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b292e100322ad74cab2ea5504f56918f/href">https://medium.com/media/b292e100322ad74cab2ea5504f56918f/href</a></iframe><p>At the time of writing this article, if you use the above intent, all your videos would be listed under the photos tab as you can see in the screenshot below (Hopefully this will get fixed soon)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OWpeblJRJG0S1JvzsmPfg.png" /></figure><p>While using these intents to select media files, you can retrieve the URI of the media file in onActivityResult, you will either get a single URI or a list of URIs depending on the type of intent you have used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/139d344f64463a058de1d2e44b601349/href">https://medium.com/media/139d344f64463a058de1d2e44b601349/href</a></iframe><p>I like the new Photo picker and since it is a dialog that pops up in an app, it feels that you are still in the app while selecting an image/video. I feel its name is a little confusing since you can use the Photo picker to select a video as well, I guess Media picker would be less confusing but naming is hard so let’s not get into it 😛 Let me know what to do you think about the Photo picker.</p><p><em>If you have feedback, feel free to tweet or message me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3823d78007a9" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/exploring-photo-picker-in-android-13-3823d78007a9">Exploring Photo Picker in Android 13</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose for Wear OS: Navigation]]></title>
            <link>https://proandroiddev.com/compose-for-wear-os-navigation-40c42bce9df7?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/40c42bce9df7</guid>
            <category><![CDATA[wearables]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Mon, 01 Nov 2021 18:25:54 GMT</pubDate>
            <atom:updated>2021-11-10T09:36:29.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pJiZFrLc3JALbTkFEkmOxQ.png" /></figure><p>In this blog post, we will learn how to implement navigation in Wear OS.</p><p>If you are interested in exploring other components in Compose for Wear OS you can check out other blogs that I have written.</p><h3>Series pitstops</h3><ul><li><a href="https://proandroiddev.com/compose-for-wear-os-scaffold-89e0fc5cc033">Compose for Wear OS: Scaffold</a></li><li><a href="https://proandroiddev.com/compose-for-wear-os-scalinglazycolumn-63f754e91edb">Compose for Wear OS: ScalingLazyColumn</a></li><li>Compose for Wear OS: Navigation (You’re here)</li></ul><p>If you have used <a href="https://developer.android.com/jetpack/compose/navigation">Navigation Component</a> while making Android apps in Jetpack Compose, you will be happy to know that the steps to implement navigation in Wear OS is almost the same. You can use the same library to implement navigation in Wear OS but it wouldn’t be optimised for the small screen. In Wear OS, the user has to swipe the app to close the current screen which is equivalent to a back press in Android. The Navigation library in Wear OS supports this by default. Let’s implement it and understand it in detail.</p><p>Add the Wear OS Navigation dependency</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/245f07c571d5c02de727fc2f0d977c21/href">https://medium.com/media/245f07c571d5c02de727fc2f0d977c21/href</a></iframe><p>We would be using SwipeDismissableNavHost from the Compose for Wear OS library. Let’s have a look at its method signature</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/566d237868368ebdbd5cd31c70026108/href">https://medium.com/media/566d237868368ebdbd5cd31c70026108/href</a></iframe><p>Hmm, that looks familiar right? The NavHost composable has the same method signature, here have a look</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8560775f8450177cc509070e02c8b958/href">https://medium.com/media/8560775f8450177cc509070e02c8b958/href</a></iframe><p>This makes it really simple to implement navigation in Wear OS if you have implemented it in Jetpack Compose, you just have to change the name of the composable from NavHost to SwipeDismissableNavHost, and you are done! Well, not really there are a few small tweaks that you need to do, which we will talk about later in the blog.</p><p>SwipeDismissableNavHost as the name suggests, adds support to swiping the screen to go back to the previous screen. SwipeDismissableNavHost can do this because it internally uses SwipeToDismissBox which takes care of handling the swipe gesture. If you don’t want to use the SwipeDismissableNavHost you can directly use SwipeToDismissBox to add support for swipe to dismiss.</p><p>Let’s have a look at the code snippet to see how to use navigation in Wear OS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9d0b9ff5fe3764cf810d320f80ab4a7/href">https://medium.com/media/c9d0b9ff5fe3764cf810d320f80ab4a7/href</a></iframe><p>This code snippet can be used to make a simple app in Wear OS that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZGUgrysj9C_qZgRtWeHuA.gif" /></figure><p>The composable method in the code snippet above may look familiar to you if you have used Navigation Component in Jetpack Compose. This composable method actually comes from androidx.wear.compose.navigation.composable The method signature of both of these composable methods are the same. You can have a look here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c05b590b1f8b3d1c0c29416992161037/href">https://medium.com/media/c05b590b1f8b3d1c0c29416992161037/href</a></iframe><p>You can provide the route, arguments, and deeplinks using this method. The composable method in Wear OS internally uses WearNavigator for navigation and the other one uses ComposeNavigator. Also if you don’t use the composable method from the Wear OS library inside SwipeDismissableNavHost, your app would crash (make sure you use the correct imports).</p><p>This is how simple it is to implement navigation in Wear OS, most composable methods in Wear OS will have a method signature that is similar to the composable methods in Android!</p><p><em>If you have feedback, feel free to tweet or message me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40c42bce9df7" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-for-wear-os-navigation-40c42bce9df7">Compose for Wear OS: Navigation</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose for Wear OS: ScalingLazyColumn]]></title>
            <link>https://proandroiddev.com/compose-for-wear-os-scalinglazycolumn-63f754e91edb?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/63f754e91edb</guid>
            <category><![CDATA[wearables]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Mon, 25 Oct 2021 02:26:08 GMT</pubDate>
            <atom:updated>2021-11-01T18:48:14.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9x7hDmwecR3f6l_-OX6PPw.png" /></figure><p>In this blog post, we will explore the ScalingLazyColumn composable. It makes adding scaling and alpha animations in a scrollable container really easy.</p><p>If you are interested in exploring other components in Compose for Wear OS you can check out other blogs that I have written.</p><h3>Series pitstops</h3><ul><li><a href="https://proandroiddev.com/compose-for-wear-os-scaffold-89e0fc5cc033">Compose for Wear OS: Scaffold</a></li><li>Compose for Wear OS: ScalingLazyColumn (You’re here)</li><li><a href="https://proandroiddev.com/compose-for-wear-os-navigation-40c42bce9df7">Compose for Wear OS: Navigation</a></li></ul><p>If you have used LazyColumn in Jetpack Compose, you will find this composable similar to it. In fact, internally ScalingLazyColumn uses LazyColumn. Let’s understand the differences between these two composables and when to use which one while making apps in Wear OS.</p><p>Let’s add the required dependencies</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/179e3151e5dc88f48600ef219100fdb8/href">https://medium.com/media/179e3151e5dc88f48600ef219100fdb8/href</a></iframe><p>Let’s have a look at the method signature of ScalingLazyColumn</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f49e9a52c99a4282003e4dcc09347b3/href">https://medium.com/media/1f49e9a52c99a4282003e4dcc09347b3/href</a></iframe><p>If you have used LazyColumn before, most of these parameters would look familiar to you. reverseLayout will lay the items of the list from bottom to top and reverse the direction of scrolling if given the true value. verticalArrangement lays the items of the list with a top or bottom alignment based on the reverseLayout value and gives a default spacing to all the items of the list. horizontalAlignment as the name suggests lays the the items of the list horizontally. Similar to other composables you can provide modifier, contentPadding, state and content to it.</p><p>scalingParams is the parameter responsible for adding the scaling and alpha animations for the list items that are at the top or bottom edge of the screen. The gif later in the blog will help you to visualise this animation. The method ScalingLazyColumnDefaults.scalingParams() takes a bunch of parameters that have default values. This is how the method signature of the above method looks like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/508797cc5a2dd8e6e490de6e94ab1c27/href">https://medium.com/media/508797cc5a2dd8e6e490de6e94ab1c27/href</a></iframe><p>I won’t go into detail about what each of these parameters is, I would suggest to just play around with these values to get the desired scaling and alpha animations for your list. All these float values are between 0f and 1f which represents the percentage of the normal values so if edgeScale has a value of 0.5f, its size will be 50% of its normal size when animated along the edge.</p><p>Let’s have a look at this video to see the difference between LazyColumn and ScalingLazyColumn</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cz_4wjhmXWwp1qQ9DgUpwQ.gif" /></figure><p>On the right, you will notice that the ScalingLazyColumn adds a subtle animation on the edges when you scroll the content inside it. While making an app in Wear OS if you want to have such animations then you should use the ScalingLazyColumn otherwise you can use LazyColumn and avoid the cost of calculating the scaling and alpha animations required for the list items.</p><p>This is the code required to implement ScalingLazyColumn like the one shown in the video</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a35c4de0d5a18a4125c627dec2c82911/href">https://medium.com/media/a35c4de0d5a18a4125c627dec2c82911/href</a></iframe><p>The composable used inside ScalingLazyColumn is Chip, it is another composable that is part of the Compose for Wear OS library. You can use it to add a material design chip in your wearable apps.</p><p><em>If you have feedback, feel free to tweet/message me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63f754e91edb" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-for-wear-os-scalinglazycolumn-63f754e91edb">Compose for Wear OS: ScalingLazyColumn</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose for Wear OS: Scaffold]]></title>
            <link>https://proandroiddev.com/compose-for-wear-os-scaffold-89e0fc5cc033?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/89e0fc5cc033</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[wear-os]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Sat, 16 Oct 2021 20:21:02 GMT</pubDate>
            <atom:updated>2021-11-01T18:46:13.864Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UfWj4SxBpqYn89rXl7a_2g.png" /></figure><p>Google recently announced that Compose for Wear OS is in Developer Preview. In this blog post, you will understand how to use Scaffold in Wear OS to build apps using different Material Design components.</p><p>If you have built Android apps in Jetpack Compose, I have good news, all components in Compose will continue to work as expected in Wear OS, it’s just that we have some additional components that have been built taking the Wear OS platform into consideration.</p><p>If you are interested in exploring other components in Compose for Wear OS you can check out other blogs that I have written.</p><h3>Series pitstops</h3><ul><li>Compose for Wear OS: Scaffold (You’re here)</li><li><a href="https://proandroiddev.com/compose-for-wear-os-scalinglazycolumn-63f754e91edb">Compose for Wear OS: ScalingLazyColumn</a></li><li><a href="https://proandroiddev.com/compose-for-wear-os-navigation-40c42bce9df7">Compose for Wear OS: Navigation</a></li></ul><h4>Let’s get started!</h4><p>Adding the Wear OS dependencies</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/179e3151e5dc88f48600ef219100fdb8/href">https://medium.com/media/179e3151e5dc88f48600ef219100fdb8/href</a></iframe><p>Just like while making an Android app we can use a Scaffold to add common UI elements like top app bar, bottom app bar etc, we can use the Scaffold from the androidx.wear.compose.material package to add the common Material Design components in a Wear OS app.</p><p>Let’s have a look at the method signature of Scaffold</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b745c641f295f771e02e6e56c58a0ab5/href">https://medium.com/media/b745c641f295f771e02e6e56c58a0ab5/href</a></iframe><p>Let me give a brief overview of all these parameters and later in the blog, we will understand each of these components in detail.</p><ul><li>vignette is the blur that you can see on the top and bottom edges of a scrollable container</li><li>positionIndicator is the scrollbar that appears on the side of your scrollable container</li><li>timeText is the time that you see at the top of your screen</li></ul><p>The following code snippet shows how we can use the Scaffold component</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6c2fc7c6402eeda4d339828cc0f53fb/href">https://medium.com/media/f6c2fc7c6402eeda4d339828cc0f53fb/href</a></iframe><p>This is how the Scaffold would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCHF2TjtXDELwvsPMMb0rA.gif" /></figure><p><strong>Note:</strong> The list implementation has been skipped on purpose to keep things simple. Let’s focus on Scaffold in this blog.</p><p>All the components used inside Scaffold are from the Compose for Wear OS library. Let’s understand how they work</p><h3>TimeText</h3><p>This component will add the time text at the top of your screen. Let’s look at its method signature</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb4360b7b43cd58ff1819e5d633cdc79/href">https://medium.com/media/cb4360b7b43cd58ff1819e5d633cdc79/href</a></iframe><p>This might look too much but it is really simple, the screenshot below might help you to understand it better. The timeSource parameter will retrieve the current time of the watch. The timeFormat() would be the format that the user has chosen for their watch whether it is in 24 hour or 12 hour format.</p><p>In Wear OS, the screen can be circular or square shaped, to make it easy to handle these scenarios we have these linear and curved parameters, the linear parameters will only be applied to square watches and the curved parameters will be applied to the circular watches. So if you want to show some text before the time text you can use leadingLinearContent or leadingCurvedContent. Similarly to show text after the time text, you can use trailingLinearContent or trailingCurvedContent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wp9jOoSedWC6iDuXdCkOsw.png" /></figure><p>The last parameter textLinearSeparator or textCurvedSeparator by default will add a “.” before or after the time text to separate it from the leading and trailing content (check it out in the screenshot above). You can customise it to add anything you want. This text separator will only be added if you use any of the above leading/trailing texts.</p><h3>Vignette</h3><p>This composable will blur the top or bottom edge of the screen slightly. Let’s have a look at the method signature</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b50abd082e3ad977f7f3e45422cb819/href">https://medium.com/media/5b50abd082e3ad977f7f3e45422cb819/href</a></iframe><p>Here we just have to provide where all we want to blur the screen. The values that we can provide to vignettePosition are Top, Bottom and TopAndBottom.</p><p>You can check the screenshot below to see how Vignette looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOYiz2pmH7xznd4bDpVokQ.png" /></figure><h3>PositionIndicator</h3><p>This component will add a scrollbar to the scrollable composable. This component has multiple method signatures as it supports multiple scrollable components, let’s have a look at one of these method signatures</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd12d2fbfdc4b19b2894270acbf69247/href">https://medium.com/media/bd12d2fbfdc4b19b2894270acbf69247/href</a></iframe><p>The parameter scalingLazyListState is the scrolling state used to implement the PositionIndicator. The reverseDirection if given the true value will make the scrollbar move in the opposite direction of the scroll so if the user is scrolling down, the scroll bar will move up. The following video may make it easier to understand the difference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FZ3zE6RdDN4UL_ywnzNYGQ.gif" /></figure><p>It’s an exciting time to be an Android developer, Jetpack Compose makes UI development enjoyable. I had fun making Wear OS apps in Jetpack Compose, I hope you enjoyed the blog post.</p><p>The GitHub repository of this sample app has been linked below</p><p><a href="https://github.com/nikit19/WearOsScaffold">GitHub - nikit19/WearOsScaffold</a></p><p><em>If you have feedback, feel free to tweet/message me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89e0fc5cc033" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-for-wear-os-scaffold-89e0fc5cc033">Compose for Wear OS: Scaffold</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write Tests for all your Missed Branches]]></title>
            <link>https://medium.com/kotlin-academy/write-tests-for-all-your-missed-branches-3c74459ed512?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c74459ed512</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Fri, 08 Oct 2021 06:02:13 GMT</pubDate>
            <atom:updated>2021-10-08T06:02:13.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kb9BKGChsgqCTalAtdB8pA.png" /></figure><p>Branch coverage is often overlooked while writing tests but if you have the knowledge of all the paths that your code can take, it will help you to understand all the edge cases. In this blog post, you will understand how to identify missing branches and write better tests for your code.</p><p>Let’s start with the basics.</p><h4>What is branch coverage?</h4><blockquote>Branch coverage is a metric that indicates whether all branches in a codebase are exercised by tests. A “branch” is one of the possible execution paths the code can take after a decision statement — e.g., an <strong>if</strong> statement — gets evaluated.</blockquote><blockquote>Source: <a href="https://linearb.io/blog/what-is-branch-coverage/">https://linearb.io/blog/what-is-branch-coverage/</a></blockquote><p>Let’s start with a simple example, we have a method that executes something based on a if condition</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/455aec32c644238640cee51198dc6c55/href">https://medium.com/media/455aec32c644238640cee51198dc6c55/href</a></iframe><p>And if we decide to only write the following test for our method</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca62f2736de45243d70dc1a7a7857c5/href">https://medium.com/media/aca62f2736de45243d70dc1a7a7857c5/href</a></iframe><p>The method will have 100% code coverage because all the lines of the method are executed while running the test but there is a missing branch, we haven’t added a test when the condition is false. If you add another test like the one below, you will be able to cover all the branches.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0560fa050971c103e0d296d260c31c2/href">https://medium.com/media/f0560fa050971c103e0d296d260c31c2/href</a></iframe><p>Now things become a little more interesting when our if condition becomes a bit more complex</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/464d2004a6c1d817f6ffd44e0903287b/href">https://medium.com/media/464d2004a6c1d817f6ffd44e0903287b/href</a></iframe><p>You might think if you add two tests like the ones below all the branches will be covered</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ccc86b6f54e5ff71d434eec2d3add6b/href">https://medium.com/media/8ccc86b6f54e5ff71d434eec2d3add6b/href</a></iframe><p>But if you have seen the cover image of this blog, you will notice that there are actually 4 branches.</p><ul><li>true &amp;&amp; true</li><li>true &amp;&amp; false</li><li>false &amp;&amp; true</li><li>false &amp;&amp; false</li></ul><p>You can write the following tests for your code to achieve 100% branch coverage</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfe3e495238c6e5a0f96b1c82086ffa4/href">https://medium.com/media/dfe3e495238c6e5a0f96b1c82086ffa4/href</a></iframe><p>Now let’s look at another example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ec45683a18cc26a363d081083586200/href">https://medium.com/media/3ec45683a18cc26a363d081083586200/href</a></iframe><p>In this example we are using the safe call operator (?.). If we write one test to check the value of name, we will miss out on the branch that can be null. So whenever we use the safe call operator we should keep in mind that it will create two branches and both of them should be tested. Now since we know that, our test cases will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ab2c9b3284717de18d25d135ae5ebe7/href">https://medium.com/media/6ab2c9b3284717de18d25d135ae5ebe7/href</a></iframe><p>Even if your tests have covered all the branches, you can always add more tests for your own understanding. In this blog post, I highlighted only the missing branches but a lot more tests can be written. I hope now you have a better understanding of all the paths/branches that your code can be executed in and you will think about these edge cases while writing unit tests.</p><p><em>If you have feedback, feel free to tweet/message me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><h3>Click 👏 to say “thanks!” and help others find this article.</h3><p>To be up-to-date with great news on Kt. Academy, <a href="https://kotlin-academy.us17.list-manage.com/subscribe?u=5d3a48e1893758cb5be5c2919&amp;id=d2ba84960a">subscribe to the newsletter</a>, <a href="https://twitter.com/ktdotacademy">observe Twitter</a> and follow us on Medium.</p><p>If you need a Kotlin workshop, check how we can help you: <a href="https://kt.academy/">kt.academy</a>.</p><figure><a href="https://kotlin-academy.us17.list-manage.com/subscribe?u=5d3a48e1893758cb5be5c2919&amp;id=d2ba84960a"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*V9G3D67yqAvCKwAlxLkvDQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c74459ed512" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kotlin-academy/write-tests-for-all-your-missed-branches-3c74459ed512">Write Tests for all your Missed Branches</a> was originally published in <a href="https://medium.com/kotlin-academy">kt.academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detect Screenshots in Android]]></title>
            <link>https://proandroiddev.com/detect-screenshots-in-android-7bc4343ddce1?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bc4343ddce1</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-apps]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 09:00:41 GMT</pubDate>
            <atom:updated>2020-11-16T11:31:36.474Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6CmkVPnHFeivrqtZkH1wg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@rmrdnl">Daniel Romero</a> on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><p>Recently I was figuring out ways to detect screenshots in Android. It turns out there is no official API to do that but there are workarounds to detect if a user has taken a screenshot while using the app.</p><p>You might have wondered how apps like Snapchat and Instagram can detect screenshots as soon as you take one. In this blog post, we will be exploring how to do that.</p><p>The approach is straightforward and to be honest when I found out what the solution is, I couldn’t believe how simple the solution was. Basically, when the user is using the app we will check the images in their device and see if a new image has been added in the “Screenshots” folder. That’s it!</p><h4>Let’s dive straight into the code</h4><p>We would be using a <a href="https://developer.android.com/reference/android/database/ContentObserver">ContentObserver</a> to observe any changes in the images in the user’s device. It takes a Handler as a parameter and the onChange method gets triggered every time there is a change detected in the URI that we specify.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9fbc266805abf589f1ce6a908e93f3e/href">https://medium.com/media/a9fbc266805abf589f1ce6a908e93f3e/href</a></iframe><p>Next, we need to register the ContentObserver, the registerContentObserver method takes three arguments. The first is the URI that the ContentObserver would be observing. The second parameter notifyForDescendants should be true if we want to observe changes for all URIs that start with the URI that we have specified otherwise if we want to be notified only when changes occur to that exact URI this parameter can be false. The last parameter is the ContentObserver that we want to register.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d2546c40b34ca1da91946109f74d0e6/href">https://medium.com/media/6d2546c40b34ca1da91946109f74d0e6/href</a></iframe><p>So now that we have registered our ContentObserver let’s see how to detect screenshots. The idea is simple whenever there is a change in the media files while the user is using the app, we will get the URI and then we will try to extract the file path from that URI. We can use the <a href="https://developer.android.com/reference/android/provider/MediaStore.MediaColumns#DATA">DATA</a> attribute of the <a href="https://developer.android.com/reference/android/provider/MediaStore.Images">MediaStore.Images</a> API to get the file path but that attribute has been deprecated in API 29, although that attribute is still there even in API 30 it is mentioned in the documentation that the developers should not assume that the file will always be available. In API 29, a new attribute called RELATIVE_PATH has been introduced. So for devices having API 29 or higher we can use RELATIVE_PATH and DISPLAY_NAME to get the file path of the screenshot file and for other devices, we can continue to use the DATA attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2d68f9fab9db3d097517605b605a6bb/href">https://medium.com/media/f2d68f9fab9db3d097517605b605a6bb/href</a></iframe><p>In the following code snippet, we are querying the DATA attribute using the URI that was returned to us from the ContentObserver. If that path contains the string “screenshot” anywhere in it, we can conclude that the user has taken a screenshot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc81ac3d504233ead78b9ca01df71d06/href">https://medium.com/media/dc81ac3d504233ead78b9ca01df71d06/href</a></iframe><p>Similarly the same can be done using DISPLAY_NAME<em> </em>and RELATIVE_PATH like it has been done in the code snippet below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95b7b617a5bac080ba7df47377bab080/href">https://medium.com/media/95b7b617a5bac080ba7df47377bab080/href</a></iframe><p>Don’t forget to unregister the ContentObserver when the user is not using your app. You can do it in the onStop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1fceebf4bada7f287a55abf518ab87f/href">https://medium.com/media/b1fceebf4bada7f287a55abf518ab87f/href</a></iframe><p>Since we are accessing the media files of the user’s device, we need to add that permission in the AndroidManifest.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff96991eb3f0a8e1a2607f871e3c172a/href">https://medium.com/media/ff96991eb3f0a8e1a2607f871e3c172a/href</a></iframe><p>So if you know any app that tracks screenshots while you are using the app, you can simply revoke this permission and the app will not be able to track when you take screenshots, I tried doing this in the Instagram app and they were not able to detect when I took a screenshot. Although if you do this in Snapchat they simply won’t allow you to use the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*uxMPeDyPOL5NhdGMDev1MA.png" /></figure><p>This solution would only work for devices that store the screenshots in the “Screenshots” folder or the file name has the string “screenshot” in it. In a stock Android device, the screenshots would be saved in the “Screenshots” folders but if the OEM decides to change that we can’t detect those screenshots. Anyway if you find an exception like that you can easily add another check for that directory since you already have the file path as it is returned from the ContentObserver.</p><p>The GitHub repository of the project has been linked below, feel free to play with the app.</p><p><a href="https://github.com/nikit19/ScreenshotDetector">nikit19/ScreenshotDetector</a></p><p><em>If you have any kind of feedback, feel free to connect with me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bc4343ddce1" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/detect-screenshots-in-android-7bc4343ddce1">Detect Screenshots in Android</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recognize Drawings using ML Kit]]></title>
            <link>https://proandroiddev.com/recognize-drawings-using-ml-kit-25e99a30a951?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/25e99a30a951</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ml-kit]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 06:08:48 GMT</pubDate>
            <atom:updated>2020-08-20T06:08:48.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*9GajCQ0VOpBrd_yW.png" /><figcaption>Photo Courtesy: <a href="https://developers.google.com/ml-kit">https://developers.google.com/ml-kit</a></figcaption></figure><p>Using ML Kit’s <a href="https://developers.google.com/ml-kit/vision/digital-ink-recognition">Digital Ink Recognition API</a>, we can recognize handwritten text or sketches made by the user on a screen. I made a simple app to play with this API as you can see in the video below, you can draw anything and the app detects it in real time. These guesses are pretty accurate and I am quite impressed, to be honest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*K2gxJZYuTWnU1oN6lXjCMQ.gif" /></figure><p>In this blog post, we will be building this app.</p><h4>Let’s start</h4><p>We need the following dependency to get started.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de9601f55a617d7fa6085fed77ae1dfe/href">https://medium.com/media/de9601f55a617d7fa6085fed77ae1dfe/href</a></iframe><p>We have to download the model that would be used to recognize the sketches and once it has been downloaded, it can be used even without the Internet. The size of the model is around 20 MB. In this example, I am using the AutoDraw model to detect sketches made by the user. The API supports 300+ language models and has shape and emoji classifiers too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26c0c88e1e4169241ef1eb6e8ab175ea/href">https://medium.com/media/26c0c88e1e4169241ef1eb6e8ab175ea/href</a></iframe><p>In the above code snippet, we initialized the modelIdentifier using a tag for the AutoDraw model. You can use any identifier of your choice. Then we use this modelIdentifier to download our model.</p><p>Before we use the model to recognize what the user is drawing, we need to create a canvas for the user to draw stuff. We can make a custom view by extending the View class and overriding the onTouchEvent method, the following code snippet shows how we can override the onTouchEvent method of our custom view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b0f3ba058b38128a7aff68eac8c56b2/href">https://medium.com/media/5b0f3ba058b38128a7aff68eac8c56b2/href</a></iframe><p>In the above code snippet, we are drawing the path that the user’s finger is traversing on the screen to a canvas. We need to send all the coordinates of this path to the Digital Ink Recognition API. This is what the addNewTouchEvent method does.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a461d24174d94582a86d51e6db301ca/href">https://medium.com/media/6a461d24174d94582a86d51e6db301ca/href</a></iframe><p>You can call the above method from your custom view every time there is a new event. Ink object is a vector representation of the user’s drawing which contains the timestamp and coordinates of each stroke that the user has made. In the code snippet above you might have noticed that a stroke starts when the user puts his/her finger on the screen and ends when the finger is lifted. This is the reason why strokeBuilder is reinitialized whenever there is an ACTION_UP event so that the next time there is a new stroke it can be added to the strokeBuilder.</p><p>This means that we are adding all the coordinates with their timestamps in strokeBuilder when the user lifts his/her finger and whenever the user starts drawing again, a new stroke with all the relevant information is added to the strokeBuilder again. Then all these strokes are added to the inkBuilder. It is this inkBuilder which constructs the ink that gets passed on to perform recognition.</p><p>Now that we have downloaded our model and have the path of the drawing with us, we can finally use this information to recognize it. The following code snippet does exactly that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7b1b5bcb75caacd4ad8fbc161b2588e/href">https://medium.com/media/b7b1b5bcb75caacd4ad8fbc161b2588e/href</a></iframe><p>The result object that is returned in the success listener contains a list of objects that can be the sketch drawn by the user. Since we are using a shape classifier, all these objects also have a score associated with them but the first object in the list is the result that the API thinks is the most accurate.</p><p>You might have noticed that in the video I was clearing the screen and making a new sketch. If you also want to do that you can simply reinitialize the inkBuilder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31519a2162948b77569a5fb43dfa5cbe/href">https://medium.com/media/31519a2162948b77569a5fb43dfa5cbe/href</a></iframe><p>That’s it, you have a fully functional app now. I remember a few years ago when I was trying to build a similar app it required me to write a lot of code for something which can be done in a few lines of code now. ML Kit libraries have simplified a lot of difficult tasks for mobile developers.</p><p>The GitHub repository of the project has been linked below, feel free to play with the app.</p><p><a href="https://github.com/nikit19/iSee">nikit19/iSee</a></p><p><em>If you have any kind of feedback, feel free to connect with me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25e99a30a951" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/recognize-drawings-using-ml-kit-25e99a30a951">Recognize Drawings using ML Kit</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Google Play Store in an Android Emulator]]></title>
            <link>https://proandroiddev.com/install-google-play-store-in-an-android-emulator-82cd183fefed?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/82cd183fefed</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[google-play]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 10:36:47 GMT</pubDate>
            <atom:updated>2020-08-07T10:36:47.071Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Avv9ECwXcn8eGZHNRzMaeQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@hoangtran7?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Louis</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Recently I was testing some Google Play Store related functionality in different emulators and I realised that it is a bit tricky to install Google Play in some emulators.</p><p>It is easy to install Google Play Store for API 24 and above as we can directly select an emulator that has Google Play from the AVD manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Wb0WfOCBVHnsxzhPqdmHg.png" /></figure><p>For emulators using API 23 and below it becomes a bit tricky as we cannot directly install an emulator from Android Studio that has Google Play installed.</p><p>In this blog post, we will see how we can install Google Play in those emulators.</p><h4>Let’s begin</h4><p>We need to download the required packages to install Google Play in the emulator based on our specifications from this <a href="https://opengapps.org/">site</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*YvRxsz8zf-qxchyo6Slmjg.png" /></figure><p>We can specify the CPU architecture and Android version of our emulator before we download the zip file.</p><p>After you decompress the zip file, you need to open the Core folder. The files that we need are highlighted in the screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*LTXm3U_TyqsZu_Sq4YFoAA.png" /></figure><p>You will notice that the files have tar.lz extension, to decompress them you can cd into the Core folder and use the following command to decompress the required files. You may need to install lzip to do that.</p><pre>tar -xf vending-x86.tar.lz</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*dmI5GCM1zQVYIDmzRhBHSw.png" /></figure><p>These are the four folders that we require to install Google Play. Each of these folders has one APK in them. Based on the configurations of your emulator you may or may not require all of them.</p><p>We can check that right now. Let’s enter the adb shell and check for the privileged apps directory using the following commands.</p><pre>adb shell</pre><pre>ls system/priv-app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*7kJFqBp7xKWFmBtzrAVYEQ.png" /></figure><p>As you can see in the screenshot above I already have APKs related to Google services installed in my emulator so I only need to install one APK that is inside the vending-x86 folder with the name Phonesky.apk.</p><p>Press Ctrl+D to exit the adb shell 😉</p><p>Now we just have to push this APK to our emulator and we are done.</p><p>We need to use the following command to start our emulator.</p><pre>$ANDROID_HOME/tools/emulator @avd_name -writable-system</pre><p>We provide the name of our emulator and this command will open the emulator in a writable environment. Otherwise, the next command will fail.</p><pre>adb remount</pre><p>This command will make /system partition of your emulator writable(By default it is readable). Now we can push the APK to the emulator using the following command.</p><pre>adb push ~/Phonesky.apk /system/priv-app/</pre><p>We provide the path to our APK and this command will copy it to /system/priv-app/ directory in the emulator.</p><p>Next we need to restart our emulator. We can use the following commands to do that.</p><pre>adb shell stop &amp;&amp; adb shell start</pre><p>Now, as soon as your emulator restarts you should be able to see the Google Play Store icon in the apps drawer. You can use it to download apps in the emulator or test any other functionality that you require.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*78_zYUcws0fbekc6HV8WKw.png" /></figure><p>I hope you were able to follow all the commands mentioned in this article if you faced any difficulties feel free to reach out to me.</p><p><em>Thanks for reading! If you enjoyed this story, please </em><strong><em>click the</em></strong> 👏 <strong><em>button and share</em></strong><em> it to help others!</em></p><p><em>If you have any kind of feedback, feel free to connect with me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82cd183fefed" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/install-google-play-store-in-an-android-emulator-82cd183fefed">Install Google Play Store in an Android Emulator</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get a list of installed apps in Android 11]]></title>
            <link>https://proandroiddev.com/how-to-get-users-installed-apps-in-android-11-b4a4d2754286?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4a4d2754286</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-11]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 20:18:50 GMT</pubDate>
            <atom:updated>2020-07-19T14:47:33.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDkj0ACHWVDFiG4cpXkyKg.jpeg" /><figcaption>Photo by NordWood Themes on Unsplash</figcaption></figure><p>In Android 11, we can see a lot of updates that improve privacy. If your app uses the PackageManager methods to get the list of installed apps in the user’s device, you will have to make some changes in your code for devices using Android 11. In this blog post, we will be discussing all our options.</p><p>If you are already querying the user’s installed apps, the following code snippet will look familiar. This is how you can get a list of installed apps of the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f99cc56b52e21495380f9baa3dc5b8eb/href">https://medium.com/media/f99cc56b52e21495380f9baa3dc5b8eb/href</a></iframe><p>Now for your users using Android 11, the code remains the same but it won’t work unless you add some additional elements in the AndroidManifest.</p><p>There are 3 different ways of querying installed apps of the user in Android 11. Let’s have a look at them:</p><h4>Query specific packages</h4><p>If you already know which apps you want to query just mention the package names inside the &lt;queries&gt; element in the AndroidManifest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05624867bf0001bccd99c26d54f9ab4f/href">https://medium.com/media/05624867bf0001bccd99c26d54f9ab4f/href</a></iframe><h4>Query using intent filter</h4><p>In case you don’t know all the package names of the apps that you want to query but there is a set of apps with similar functionality that you want to query then you can use an intent filter inside the &lt;queries&gt; element according to your requirements like it has been done in the code snippet below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f28a83bac02243774dbd3e75ca4f56b/href">https://medium.com/media/6f28a83bac02243774dbd3e75ca4f56b/href</a></iframe><p>The &lt;intent&gt; element looks like &lt;intent-filter&gt; but there are few differences. &lt;intent&gt; element has the following restrictions:</p><ul><li>The &lt;intent&gt; element can have only one &lt;action&gt; element.</li><li>The &lt;data&gt; element can only have the following attributes : mimeType, scheme and host.</li></ul><h4>Query all the apps</h4><p>If you want to query all the apps of the user like you were doing earlier, you need to include <a href="https://developer.android.com/reference/kotlin/android/Manifest.permission#query_all_packages">QUERY_ALL_PACKAGES</a> permission in the AndroidManifest. It is a normal permission and it is granted as soon as the app is installed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4df65fec42410cff91ebe640781a6c8d/href">https://medium.com/media/4df65fec42410cff91ebe640781a6c8d/href</a></iframe><p>Ideally one should request the least amount of packages and respect the user’s privacy. In most cases this permission won’t be required, only for apps like launchers it makes sense to ask the user for permission to query all the installed apps on their phone.</p><p>There is one loophole that I noticed while exploring the &lt;queries&gt; element if you add android.intent.action.MAIN as the action element in the intent filter, you can see almost all the apps of the user without adding the permission since almost all apps would have this element in the AndroidManifest.</p><p><em>Thanks for reading! If you enjoyed this story, please </em><strong><em>click the</em></strong> 👏 <strong><em>button and share</em></strong><em> it to help others!</em></p><p><em>If you have any kind of feedback, feel free to connect with me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4a4d2754286" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/how-to-get-users-installed-apps-in-android-11-b4a4d2754286">How to get a list of installed apps in Android 11</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animations in Jetpack Compose using Transition]]></title>
            <link>https://proandroiddev.com/animations-in-jetpack-compose-using-transition-25d5d2143401?source=rss-1c3fe5ef9e81------2</link>
            <guid isPermaLink="false">https://medium.com/p/25d5d2143401</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nikit Bhandari]]></dc:creator>
            <pubDate>Tue, 14 Apr 2020 17:47:39 GMT</pubDate>
            <atom:updated>2020-04-14T18:02:35.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUZyQWbL0sqRG8rbZ46cuA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@nervum?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jack B</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this blog post, we will understand how we can use different types of animations in Jetpack Compose using Transition.</p><p>If you are interested in exploring other components in Jetpack Compose you can check out the series of articles that I have written.</p><h3>Series Pit Stops</h3><ul><li><a href="https://proandroiddev.com/how-to-make-a-recyclerview-in-jetpack-compose-fd54417d8479">How to make a Scrollable list in Jetpack Compose?</a></li><li><a href="https://proandroiddev.com/handling-clicks-in-jetpack-compose-3800379845c4">Handling Clicks in Jetpack Compose</a></li><li><a href="https://proandroiddev.com/creating-appbars-in-jetpack-compose-a8b5a5639930">Creating AppBars in Jetpack Compose</a></li><li><a href="https://proandroiddev.com/how-to-use-tabs-in-jetpack-compose-41491be61c39">How to use Tabs in Jetpack Compose?</a></li><li><a href="https://android.jlelse.eu/exploring-drawers-in-jetpack-compose-3131e6f1b07b">Exploring Drawers in Jetpack Compose</a></li><li><a href="https://proandroiddev.com/exploring-adapterlist-in-jetpack-compose-1615865d8e7d">Exploring AdapterList in Jetpack Compose</a></li><li>Animations in Jetpack Compose using Transition (You are here)</li></ul><p>As I mentioned earlier we will be using a composable called Transition to create beautiful animations in this article, so let’s have a look at the method signature of Transition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815f271c95a27766c589d3fc270fc739/href">https://medium.com/media/815f271c95a27766c589d3fc270fc739/href</a></iframe><p>TransitionDefinition consists of all the information related to the animation that will be required as we transition from one state to another. We will discuss about it in detail later in the article. initState defines the initial state of the transition when it is undefined it takes the value of the first toState seen in the transition. toState as the name suggests is the next state in our transition. clock is an optional parameter that drives the animation as time changes. onStateChangeFinished is an optional listener to get notified when a state change animation has finished. children is the composable that will be animated.</p><p>In a TransitionDefinition we will define all animations and states of the animation we are using. There are few predefined animation builders that we can directly use. Let’s have a look at them first.</p><h4><strong>Tween</strong></h4><p>It is used to animate from one value to another by providing the duration of the animation, delay and easing. The following code snippet can be used to create a tween animation in TransitionDefinition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e03506da0b55ea346c4d35eabe005b/href">https://medium.com/media/26e03506da0b55ea346c4d35eabe005b/href</a></iframe><h4>Physics</h4><p>It is used to create spring animations, we can provide values for damping ratio and stiffness. The following code snippet can be used to create a physics animation in TransitionDefinition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c1e26e0255d71029df2ef9c661c577f/href">https://medium.com/media/9c1e26e0255d71029df2ef9c661c577f/href</a></iframe><h4>Keyframe</h4><p>It is used to create animations based on values at different timestamps. The timestamps can be defined using the infix function at. We can also provide easing for the animation using the infix function with.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14266e88688f7fac071ba3766076ce09/href">https://medium.com/media/14266e88688f7fac071ba3766076ce09/href</a></iframe><h4>Snap</h4><p>It used to switch immediately from one animation state to another.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc3bbdbfbd5c309286f26cdc544c0d9/href">https://medium.com/media/6dc3bbdbfbd5c309286f26cdc544c0d9/href</a></iframe><h4>Repeatable</h4><p>It takes another animation as a parameter and can be used to repeat it as many times as we want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f01445ddc06949189578c4d62eeda2f/href">https://medium.com/media/1f01445ddc06949189578c4d62eeda2f/href</a></iframe><p>Now that we have an idea about all the predefined animation builders let’s understand how to create a TransitionDefinition. It basically consists of 3 steps:</p><h4>Create PropKeys</h4><p>The first step is to create PropKeys. It is required for each property that needs to be animated so that we can change their values as we move from one state to another. For example, if we require float values then we can use FloatPropKey likewise for different use cases, we can use different types of PropKeys like PxPropKey, ColorPropKey etc.</p><h4>Create State names</h4><p>It is recommended to create state names for different checkpoints in the animation. State names are generic so they can be integer, string, enum or anything that you feel suits your use case.</p><h4>Create the TransitionDefinition</h4><p>We will be using the animation DSL to create the TransitionDefinition using PropKeys, StateNames and the animation of our choice.</p><p>Let’s understand the entire process of creating an animation in Jetpack Compose using an example. In the following code snippet, we have created a TrasitionDefinition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ea5276f6fefe2d22c774ef22080f8c6/href">https://medium.com/media/3ea5276f6fefe2d22c774ef22080f8c6/href</a></iframe><p>We have made a PropKey of type float. Our TransitionDefinition has two states start and end. Our PropKey will vary from 0f to 360f. We are using a repeatable animation which uses a tween animation.</p><p>Now that we have defined our TransitionDefinition let’s pass it to the Transition composable and perform the animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/581904ccf1ad89bc482f246b0e8d066c/href">https://medium.com/media/581904ccf1ad89bc482f246b0e8d066c/href</a></iframe><p>In the above code snippet we have passed our TransitionDefinition and declared the initial and final state of the transition. Then we are using the canvas to draw the animation, we are simply making three concentric circles and passing the state[angle] as a parameter to the drawArc function. The value of state[angle] will vary from 0f and 360f, this is how we are making a circle using the drawArc function.</p><p>The result of the above code can be seen in the GIF below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*UmjbFLrBXhLCJqHaQwFeNQ.gif" /></figure><p>Conceptually it might seem that there are a lot of steps involved but if you look at the code, you will realize I barely wrote anything.</p><p>The code snippets used above are from this repository, feel free to check it out.</p><p><a href="https://github.com/nikit19/AnimationsJepackCompose">nikit19/AnimationsJepackCompose</a></p><p>Jetpack Compose is still in developer preview, there will be breaking changes in the future so some of the things that I mentioned might change over time.</p><p><em>Thanks for reading! If you enjoyed this story, please </em><strong><em>click the</em></strong> 👏 <strong><em>button and share</em></strong><em> it to help others!</em></p><p><em>If you have any kind of feedback, feel free to connect with me on </em><a href="https://twitter.com/NikitBhandari"><em>Twitter</em></a><em>.</em></p><p><a href="https://twitter.com/NikitBhandari">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25d5d2143401" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/animations-in-jetpack-compose-using-transition-25d5d2143401">Animations in Jetpack Compose using Transition</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>