The example writes to a file with KotlinFiles.writeextension function. Files.write(myfile.toPath(), content.toByteArray(), StandardOpenOption.APPEND) The first parameter of theFiles.writeis thePathto the file, the second is the byte array to write, and the third parameter are the options ...
When I was starting to write Kotlin code, and one problem I faced was how the heck do I do static methods like I can add in Java? The solution… The companion object in your Kotlin class. class MyClass() { companion object { fun myStaticMethod() { //Do Stuff Here } } } Accessing...
CameraX aims to demonstrate how to use CameraX APIs written in Kotlin. Overview CameraX is a Jet-pack support library, built to help you make camera app development easier. It provides a consistent and easy-to-use API surface that works across most Android devices, with backward-compatibility ...
A tutorial on how to write an iOS App that uses a web service. Comes with a companion tutorial showing you how to make the web service itself!
Many people think that there is some kind of kotlin magic here that cancels type erasure for Java generics. But in fact, reified is just a side effect of code inlining and there is no magic here. To demonstrate this, let’s put this magic under a microscope. If you try to write such...
Let’s assume you are working on Kotlin Multiplatform project. You need to retrieve the GPS position of the user from common code, and there’s no library out there that does so. That’s when you decide to write a new Kotlin Multiplatform library that abstracts GPS location on both Andr...
Usewhenin Kotlin Without Arguments We can also use thewhenexpression without giving any arguments. It means that we can use the expression and then start writing the code block to execute. We can write conditional statements in the block. When a condition becomes true, the adjacent statement is...
To use this, add this to your gradle build file: implementation 'org.osmdroid:osmdroid-shape:VERSION' In Kotlin valfolder:List<Overlay>=ShapeConverter.convert(mapView,File(myshape)) mapView.overlayManager.addAll(folder) mapView.invalidate() ...
The HTTP POST method sends data to the server. It is often used when uploading a file or when submitting a completed web form. Kotlin GET request with HttpClient HttpClientis a tool for generating http requests in Java. GetRequest.kt
Kotlin provides a great feature through data classes in order to eliminate a lot of boilerplate code like constructors, getter/setters, toString method, etc that you would usually write in order to achieve the same functionality in various other programming languages likeJava, C#, etc. ...