Posts

Showing posts with the label Kotlin Course

OOPS Concepts in Kotlin

  Kotlin is a modern, statically-typed programming language that fully supports   Object-Oriented Programming (OOP)   concepts. Below is an explanation of the four main OOP concepts in Kotlin, along with examples. 1.   Encapsulation Encapsulation is the practice of bundling data (properties) and methods (functions) that operate on the data into a single unit, called a   class . It also involves restricting direct access to some of an object's components, which is achieved using   access modifiers .

Kotlin Android Program (QCR) Application Codes That Read Text in Photos

Kotlin Android Program (QCR) Application Codes That Read Text in Photos To write a program to convert text from a photo to text (Optical Character Recognition) with Kotlin, libraries such as Google's **ML Kit** or **Tesseract OCR** ​​are typically used. In this example, we will develop a simple OCR application using Google ML Kit. This application allows the user to select a photo and translate the text in the photo. ---  1. Project Setup - Create a new project in Android Studio. - Select the `Empty Activity` template. ---

Kotlin Hello World

fun main(args: Array<String>) {     println("Hello, World!") } Explanation:  * fun main(args: Array<String>):    * This line defines the main function, which is the entry point of the Kotlin program.    * fun is the keyword for declaring a function.    * main is the name of the function.    * args: Array<String> is the parameter of the main function, which represents an array of command-line arguments passed to the program.  * println("Hello, World!"):    * This line prints the text "Hello, World!" to the console.    * println() is a built-in function in Kotlin that prints the given string to the console and adds a newline character at the end. To run this code:  * Save the code: Save the code in a file named HelloWorld.kt.  * Compile the code: Use the Kotlin compiler (kotlinc) to compile the code:    kotlinc HelloWorld.kt -include-runtime -d HelloWorld.jar  * Run t...

Kotlin MP3 Player Example

  First    we add the following permission to the Manifest file <uses-permission android:name = "android.permission.FOREGROUND_SERVICE" /> Then we add the following libraries to Gradle Dependencies implementation ("androidx.media3:media3-exoplayer:1.2.1") implementation ("androidx.media3:media3-ui:1.2.1") implementation ("androidx.media3:media3-common:1.2.1") implementation( "androidx.media3:media3-session:1.2.1") We synchronize them (we SYNC).  We add the following "val" into the Main Activity. val player = ExoPlayer . Builder ( context ). build () val mediaSession = MediaSession . Builder ( context , player ). build () To take this player to a more advanced level We add the following code into the main activity. class PlaybackService : MediaSessionService () {     private var mediaSession : MediaSession ? = null     // Create your Player and MediaSession in the onCreate lifecycle event     override fun...