This article shows a step by step guide to capture a photo with camera in Android using Kotlin. For this purpose, we need to initialize an Intent with MediaStore.ACTION_IMAGE_CAPTURE Action. Then open native Camera App using startActivityForResult(…), as shown in the following code. 1. Add Camera Permission Before starting, add the following CAMERA permission in your Manifest.xml file […]
How to Save and load Image from Cache Using LruCache in Kotlin Android
It’s a common requirement when we have to save our Images/Bitmaps into the cache in Android. For this purpose, we can use LruCache. Although most of the time while loading images from the server, we use some third party image caching libraries like Picasso, Glide, or Fresco. But if the image is not coming from […]
Method to Remove Consecutive Characters from a String in Kotlin Android
Recently I can across to the problem when I have to remove consecutive characters from a String in Kotlin. My requirement was to allow a maximum of 2 same characters. For this purpose, I have written a generic method to Remove extra same repeating and duplicate Characters from a String in Kotlin. Following is the […]
How to Show Vertical List in Kotlin using RecyclerView Example
As you know we can use RecyclerView in Android to populate long lists. Using RecyclerView we cannot only populate vertical lists. But we can also populate Grid & horizontal lists. In this article, we will discuss how you can show vertical list in Kotlin using RecyclerView. By following the code explained in the article, you […]
How to Get App Version Name in Kotlin Android
Sometimes we have to get the current App version in Android to send it to our server or to show App update popup. You can use the following method to get the App Version Name in Kotlin Android. fun GetAppVersion(context: Context): String { var version = “” try { val pInfo = context.packageManager.getPackageInfo(context.packageName, 0) version […]
AlertDialog with Custom XML Layout in Kotlin Android
We use AlertDialog class to show popups in Android. But sometimes default AlertDialog’s layout is not enough to fulfill our requirement. So that we have to create Alert Dialog with custom layout. This article explains how to create AlertDialog with Custom XML Layout in Kotlin Android. Basic Kotlin Code to populate Custom XML Layout in […]
Inflate Layout at Runtime in Kotlin Android
In this article, you will learn how to inflate one layout in another at Runtime using Kotlin in Android. To populate very few items, we can embed or inflate them on runtime. But for a long list, its always better to use RecyclerView. Following is the basic code to inflate one layout in another in […]
Basic RecyclerView Custom Adapter in Kotlin Android
We use RecyclerView in Android to show a list or grid of items. For that, we have to write the RecyclerView Custom Adapter to populate data to each item of the list. In the following code, I have shared a very simple & basic RecyclerView custom adapter in Kotlin. You can just copy-paste this code […]
Lint found fatal errors while assembling a release target Android
I recently found that people are struggling while generating a release APK from Android studio with the error, “Lint found fatal errors while assembling a release target”. Although their App is running successfully in Debug mode. This error happens when we have some issues in some XML files or some other issue not allowing the […]
Ask Runtime Permission in Kotlin Android
As we all know from API level 23 (Android 6.0) and above, we need to ask Runtime Permissions in Android App. The following article contains utility methods to ask runtime permission in Kotlin Android. This code also shows an Alert Dialog to the user to allow permissions from App Settings, if the user denies permission […]