Skip to main content

Posts

Showing posts from June, 2021

onBackPressed() method is deprecated, you are looking for an alternative? Here It is the Latest Solution in android | Kotlin

Recycler View Like Google Play Store App | How to use SnapHelper Android, Kotlin

 If we see the google play store android app, we can see that the app list in horizontal recycler view hold a property that the first property hold always full visible or not visible, but a portion visible is not seeing. This property is snap property. In this article I show you how to use it in our own application. Basically we use two type of snap. Center Snap and start snap. I show you both here. So read full article here. The Key Moment code is here- For center snap you need to write 2 lines code- //center Snap val snapHelper = LinearSnapHelper() snapHelper.attachToRecyclerView(recyclerView1) For start snap, create a class in kotlin say StartSnapHelper.kt package com.example.snaphelpersampleapp import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSnapHelper import androidx.recyclerview.widget.OrientationHelper import androidx.recyclerview.widget.RecyclerView class StartSnapHelpe

How to compare between two JSON online.

 In many times in our development time we need to compare between two JSON Object are equal or not. For simple JSON Object which has contain with 3-4 key-value pair is easy for us to compare it by us, but for complex JSON it is very difficult two compare between them. So in this article I show you how you easily compare between two JSON. For that case you need to visit  http://www.jsondiff.com/ As example, Using this site we compare between two json object Sample JSON 1 { "name" : "John Doe" , "roll_no" : "25" , "is_present" : true } Sample JSON 2 { "name" : "John Doe" , "roll_no" : "25" , "is_present" : false , "div" : "A" } So first we open the site and in left and right side input box just copy paste the sample JSON 1 and sample JSON 2 and click on the "Compare" button which placed in centre. Now you can easily see the difference as per

How to check internet availability in kotlin | Android

 Internet availability check for any standard application is necessary. When you call an Rest API or any internet related task execution, you must need to check the internet availability in your application. So In this article, I show you how to check the internet availability in android | Kotlin  So, First in your project add the INTERNET and ACCESS_NETWORK_STATE permission in menifest.xml <uses-permission android:name= "android.permission.INTERNET" /> <uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE" /> Make a function in kotlin, that return true if internet connection is available else it return false fun isOnline (context: Context): Boolean { val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork: NetworkInfo? = cm.activeNetworkInfo return activeNetwork?.isConnectedOrConnecting == true } Now, simply you c

Analyze your build with APK Analyzer | How to analyze .apk or .aab file in android studio

 One of the best feature in android studio is apk Analyzer. Here you can understand the size of .apk file or .aab how to build. You can take decision,  that how to optimize the apk or aab file size. So in this article I show you how to analyze apk file in android studio. You can analyze your build apk and also outside of the project. So read this article- First you can build a .apk or .aab file of your project. After build successful you can see a notification pou-up in bottom-right side corner that the apk build is successful. Here you see two linked text "Locate" and "analyze". Now you need to click on "analyze".    After click on Analyze, you can see the analyze report on your android studio window. Here you check the dex file size, all the res files i.e drawable, mipmap, string etc how much take the memory in your apk file. See the below screenshots, so you can better understand- See this video, so you can understand it- Also You can analyze apk file t

How to create Get it on Google play Batch in 5 minutes | How to Get a Google Play badge?

 If you publish your application in play store and thinking that for your app promotion in any website or printing "Get it on Google play" batch. Don't worry, no need to do anything for it. Google provide it. It is need 5 minutes to make this batch.       So In this article, I show you how to get this batch. Before that you need to know some basic rules for make this batch The rules as per Google is that- 1. Use the badges as provided. Never alter the badges. 2. There must be clear space surrounding the badge equal to one-quarter the height of the badge. 3. The badge must be large enough that all of the text is legible. 4. The Google Play badge should be the same size or larger than other application store badges. 5. Badges must be shown on a solid colored background or a simple background image that does not obscure the badge. 6. Match the badge language to the language of your marketing campaign whenever possible. 7. Any online use of the badge must link to the Google P

Convert JSON to Kotlin Model class Using GSON, in 5 seconds, Android | Kotlin

 As a Native android developer, it is very difficult to parse a complex JSON in our application. Normally the rest api json structure is much complex to parse it using functions as getObject(), getString(), getBoolean() etc. So, In order to overcome this problem also for save time we use GSON. Many developers already know that, but here I give you a simple and short solution that, you can convert JSON to Kotlin Model class for any complex JSON within 5 seconds. So Just follow the guidelines- Okay, First you can add the gradle dependency of GSON implementation 'com.google.code.gson:gson:2.8.6' Now I can take a sample JSON, which I make model class and then parse. Below I mentioned the sample json- { "problems" : [ { "Diabetes" : [ { "medications" : [ { "medicationsClasses" : [ { "className" : [ {

Create Any Recyclerview Adapter within 5 seconds, in Android | Kotlin.

 In every single android application, we need to make many number of recycler-view adapter. So every time you create a blank adapter and modify it as per your requirements. But it is very boring and as well as time taking. So here I give you a solution that you can create any recyclerview adapter within 5 seconds using file template in Android Studio. So, Lets read this full article- First we open android studio and create a project. After project creation  Open File->new->Edit File Template... Follow this below screenshot Okay, After click on "Edit File Template" a popup is open "File and Code Template", Now click on the  " + " icon and set set your template name. Now set your template name, template extension and template body. after doing everything click on "Apply" and then click on "OK" The template body I after after the screenshot Template Body Copy this code and paste it on the template body section, which I marked in scre

Popular posts from this blog

How to Insert Multiple rows in a single db transaction in Android Room Database? | Android | Room DB

  To insert multiple rows into a Room database in Android, you can follow these steps: 1. Set up Room Database: First, make sure you have set up your Room database correctly in your Android project. Define your Entity class, create a Database class that extends RoomDatabase, and set up your DAO (Data Access Object) interface. 2. Create Entity Class: Define an Entity class that represents the data you want to insert into the database. For example: 1 2 3 4 5 6 7 8 9 @Entity (tableName = "my_table" ) public class MyEntity { @PrimaryKey (autoGenerate = true ) public int id; public String name; public int age; // Add other fields and getters/setters as needed } Create DAO: Create a DAO interface with a method to insert multiple rows. For example: 1 2 3 4 5 @Dao public interface MyEntityDao { @Insert void insertAll (List<MyEntity> entities); } Initialise Database and DAO: In your application code, create an insta

Recycler View Like Google Play Store App | How to use SnapHelper Android, Kotlin

 If we see the google play store android app, we can see that the app list in horizontal recycler view hold a property that the first property hold always full visible or not visible, but a portion visible is not seeing. This property is snap property. In this article I show you how to use it in our own application. Basically we use two type of snap. Center Snap and start snap. I show you both here. So read full article here. The Key Moment code is here- For center snap you need to write 2 lines code- //center Snap val snapHelper = LinearSnapHelper() snapHelper.attachToRecyclerView(recyclerView1) For start snap, create a class in kotlin say StartSnapHelper.kt package com.example.snaphelpersampleapp import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSnapHelper import androidx.recyclerview.widget.OrientationHelper import androidx.recyclerview.widget.RecyclerView class StartSnapHelpe

How to fetch Latitude, Longitude from address and vice-versa(address from Latitude, Longitude) using Google Geo coder SDK in android| Kotlin

 In this Android development related article, you will get a simple solution that, how to get address using Latitude, Longitude and vice-versa. i.e latitude, longitude from an address text. It is very easy and simple. Read full article and carefully follow all the steps. Here we use google Geocoder SDK. Okay, first we create an android project in kotlin and create an Activity say MainActivity.kt. Use the below code- Function get Latitude, Longitude from Address- fun getLatLngFromAddress (context: Context, mAddress: String): String { val coder = Geocoder(context) lateinit var address: List<Address> try { address = coder.getFromLocationName(mAddress, 5 ) if (address == null ) { return "Fail to find Lat,Lng" } val location = address[ 0 ] return " Latitude: ${location.latitude}\n Longitude: ${location.longitude}" } catch (e: Exception