Skip to main content

Posts

Showing posts with the label Kotlin

Simplify Your Tax Calculations with GST Calculator 2024: The Ultimate Tool for Businesses and Individuals

Mastering Kotlin Generics: Understanding and Deep Dive of In, Out, and Where

Kotlin, a modern statically typed programming language, offers many powerful features to streamline coding, one of which is its support for generics. Generics enable you to write flexible and reusable code, allowing types to be parameters when defining classes, interfaces, and functions. Understanding the intricacies of generics is crucial for leveraging Kotlin's full potential. In this blog, we'll delve into the concepts of in , out , and where in Kotlin's generics. What Are Generics? Generics are a feature that allows you to define classes, interfaces, and methods with placeholder types. This way, you can create more flexible and reusable components. For instance, you can create a List<T> that can hold any type T , rather than creating separate classes for each type. class Box<T>(val value: T) fun main() { val intBox = Box(1) val stringBox = Box("Hello") } In this example, Box<T> is a generic class where T ...

SearchView in Android with RecyclerView | Toolbar | Kotlin

 The search functionality in android App is a very important feature of any list page. In this article I make a simple android application to describe the SearchView integration in Android with RecyclerView | Toolbar | Kotlin. Follow the steps- Step 1 :  First create a blank project in android studio with simple empty activity. Step 2 :  Use the below code in colors.xml file <?xml version="1.0" encoding="utf-8"?> <resources> <color name= "purple_200" > #FFBB86FC </color> <color name= "purple_500" > #FF6200EE </color> <color name= "purple_700" > #FF3700B3 </color> <color name= "teal_200" > #FF03DAC5 </color> <color name= "teal_700" > #FF018786 </color> <color name= "black" > #FF000000 </color> <color name= "white" > #FFFFFFFF </color> </resources> Step ...

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...

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...

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

 One of the most used method OnActivityResult is deprecated in android. Here it is the alternative solution you can follow- People photo created by pressfoto - www.freepik.com In First Activity, take val  resultLauncher using below code- private val resultLauncher = registerForActivityResult(StartActivityForResult()) { result -> if (result.resultCode == Activity.RESULT_OK) { try { val data: Intent? = result.data                     val stringResponse = data?.getStringExtra( "response" )!! } catch (e: Exception) { e.printStackTrace() } } } Now Call this val, where you want to make startActivityFor Result override fun onCreate (savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) button...

How to get Android Device Current locaction, i.e latitude and longitude in Kotlin Using Fused Location SDK.

  In this Android development article, you will learn, how to get device current location in android kotlin using Google Fused Location Client SDK. Now a days, device current location fetching is a common feature in many applications, and for us we need to write same code in every project. So I make this code in such a way that, we can integrate the device location pick feature (i.e latitude, longitude ) within 5 minute. Just follow this steps- Okay, first we create an android project and create a activity  MainActivity.kt and respective xml file is activity_main.xml Add Location Permission in AndroidMenifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "com.example.devicecurrentlocation" > <uses-permission android:name= "android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name= "android.permis...

Popular posts from this blog

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...

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...

How to consume REST APIs in Laravel | Laravel Development | Solution

In Laravel, you can call a REST API using the HTTP client provided by the framework. Laravel's HTTP client allows you to make GET, POST, PUT, DELETE, and other HTTP requests to external APIs. Here's how you can call a REST API in Laravel: Install Laravel (if not already done): If you haven't already set up a Laravel project, you can create one using Composer by running the following command: composer create - project -- prefer - dist laravel / laravel project - name Create a Controller (optional): You can create a controller to encapsulate the API call logic, but this step is not strictly necessary. You can also make API calls directly from your routes or other parts of your application. To create a controller, run the following command: php artisan make: controller ApiController Make an API Request: You can make API requests using Laravel's HTTP client, which is a fluent, expressive interface for making HTTP requests. Here's how you can make a simple GET request t...