https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
stackoverflow
  • u

    user

    07/18/2022, 1:21 PM
    How do i apply a default font to all Text() elements in the app using Jetpack Compose? I need to apply a common font to all the Text() used in my entire app. Currently i am applying it manually to each text using a style or font as follows. How can i specify this as a global theme for the app? In normal xml layouts, i was using a custom TextView widget to achieve this. Text( text = stringResource(id = R.string.userName), style = typography.h2, fontSize = 20.sp, )
  • u

    user

    07/18/2022, 1:41 PM
    Convert Live Data to kotlin flow in jetpack compose Hey I am new in jetpack compose. I am checking in internet is available or not and consume through live data. Now I started learning jetpack compose so I want to use Flow, So any guys help me to convert this LiveData to flow and use in jetpack compose. NetworkConnection.kt import android.app.Application import android.content.Context import android.net.ConnectivityManager import android.net.Network import android.net.NetworkRequest import androidx.lifecycle.LiveData class...
  • u

    user

    07/18/2022, 1:41 PM
    How can I connect to a network service on hosting OS from Multiplatform commonTest I am testing out KMM, and having a KMM library connecting to a grpc service on hosting machine. I then have a simple test in commonTest, trying to make the connection to the service. I then run the test from AS, choosing Android as the target. However, I simply cannot make it work: If I use localhost as the destination host, I get a connection rejection error. Then I thought maybe this is running from Android emulator, so I use 10.0.2.2. This gives me Operation timed out error. So, what is...
  • u

    user

    07/18/2022, 1:41 PM
    Failed to resolve: com.github.unsplash:unsplash-photopicker-android:1.0.1 I was trying to make a new project starting with dependencies when I got this: 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugAarMetadata'.
    Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
    > Could not find com.github.unsplash:unsplash-photopicker-android:1.0.1. Searched in the following locations: -...
  • u

    user

    07/18/2022, 2:01 PM
    How to get transparent while erasing the canvas in Jetpack Compose , now I'm getting white color? Canvas( modifier = modifier .background(Color.Transparent) ) { with(drawContext.canvas.nativeCanvas) { val checkPoint = saveLayer(null, null) drawImage( image = bitmap, srcSize = IntSize(bitmap.width, bitmap.height), dstSize = IntSize(canvasWidth, canvasHeight) ) drawPath( path = erasePath, style = Stroke( width = 30f,...
  • u

    user

    07/18/2022, 2:21 PM
    JetpackCompose how to createChooser and listen for result I want to show a system dialog to user to select from available applications for sharing text from my app. I can do this by using createChooser function from Intent class. But i also want to listen for the system dialog result, so that i can disable/enable my share button to prevent creating multiple system dialogs overlapping each other. To do this i need to know whenever the dialog is dismissed or an app option is selected by the user. So i need the result of the chooser Dialog i have...
  • u

    user

    07/18/2022, 2:41 PM
    Global jackson configuration does not work (Kotlin, Spring-Boot) i am not able to get ISO formatted dates. Setup: Kotlin 1.7.10 Spring Boot 2.7.1 Jackson 2.13.3 with following jackson dependencies: jackson-module-kotlin jackson-databind Application properties spring: jackson: date-format: "yyyy-MM-dd'T'HH🇲🇲ss.SSS'Z'" default-property-inclusion: non_null serialization: write-dates-as-timestamps: false INDENT_OUTPUT: true deserialization: FAIL_ON_UNKNOWN_PROPERTIES: false...
  • u

    user

    07/18/2022, 2:41 PM
    How to show only avg and max values in labels on Y axis using MPAndroidChart? I have graph which show speed value on Y axis. I want to show exactly 2 values: avg value (i. e. middle value label) and max value. I'm using YAxis.setLabelCount(2) to set only two labels on Axis. But graph always showing me min value and another one or two values. The behavior that i want: If we have max speed 2.4 miles (or km) - show label with max speed. Also show half from this speed label (1.2)

    https://i.stack.imgur.com/MfTty.pngâ–¾

  • u

    user

    07/18/2022, 2:41 PM
    Kotlin: I have a problem while switching from one Activity to another? I have a problem when I want to switch between two activities. This is my code on the first activity. I want to switch to the CatDoorActivity. modifier = Modifier.clickable { val intent = Intent(this, CatDoorActivity::class.java) intent.putExtra("UUID", deviceUUID).putExtra("TITLE", deviceTitle) this.startActivity(intent) } My Problem is this exception after running that code: android.content.ActivityNotFoundException: Unable to find explicit...
  • u

    user

    07/18/2022, 2:41 PM
    How to parse a epub file in the android I'm trying to get the contents of a epub file and output the content through text-to-speech in an android application. I'm unable to find any helpful resource or library for the same. Any suggestion or resources for the same would help. Thanks in advance.
  • u

    user

    07/18/2022, 3:01 PM
    Android - Open app when device F10 key press We built a USB device (Type-C) that connects to Android phone using charging input and pressing the F10 key on the phone. What I am looking for is to listen for a USB device and F10 key. When these detect our app must launch. (I think I can listen for USB using Broadcast receivers) Note: This must work in the background even when the phone is locked. My question is how can I listen for the F10 key when a USB device connects to the phone? Be aware that I want to open our app when the above...
  • u

    user

    07/18/2022, 3:41 PM
    Kotlin Flow collector gets the initial value only then stops one question in Flow... why am I getting the initial value only? despite that I emit a new value in the ViewModel, and the value in the MutableStateFlow changes. but the collector doesn't get any... I change the value from the MainActivity using a menu action: R.id.settings -> viewModel.updateMoveToSettings(true) and in the viewmodel I emit it this way private val _moveToSettings = MutableStateFlow(false) val moveToSettings get()= _moveToSettings fun updateMoveToSettings(value: Boolean)...
  • u

    user

    07/18/2022, 3:41 PM
    SimpleDateFormat Unparseable date only on phone I need to parse a string from my database which has "Mon Jul 18 12:58:05 2022" string as value. Weirdly it only works with emulator. But, if i try to uses my app in my phone it throws Unparseable date error. My phone is using android 9 which use sdk 28, so i think it should be fine. I alread tried to remove the timezone which in many cases could cause the problem. But, after i remove it and the error still happen. It took me sometime to figure this out, but in the end i still got no answer. I...
  • u

    user

    07/18/2022, 4:01 PM
    Where to set Visibility to False in Jetpack Compose? Relaunching Animation everytime Composable comes into view? I would like to relaunch an animation everytime it comes into view, meaning if I scroll down a little with composable out of view, then scroll back up, the animation should relaunch. All the examples I've been seeing people have been setting the visibility to false with a button, however, I do NOT have a button. I would like it to be set whenever the composable is OUT of view. This is what I have so far: @Composable BarComponent{ var visible by remember { mutableStateOf(false) }...
  • u

    user

    07/18/2022, 4:01 PM
    HackerRank Project Euler #1 Kotlin I'currently training Kotlin using Project Euler based programming challenges on HackeRank. Today I have been working on the first challenge:

    https://i.stack.imgur.com/ALMbB.pngâ–¾

    My first solution was: import java.util.Scanner fun main() { val sc = Scanner(System.
    in
    ) val numberOfInputs = sc.nextInt() val inputs = IntArray(numberOfInputs) for (index in 0 until numberOfInputs) { inputs[index] = sc.nextInt() } for...
  • u

    user

    07/18/2022, 4:21 PM
    KotlinJS with React-Router-Dom, How to use the location state? I have a kotlin multiplatform project that has a jvm server and a KotlinJS client that uses kotlin-wrappers such us kotlin-react and react-router-dom. I recently updated the wrappers version and they changed the way that the NavigateOptions' state works. Before, i had something like this: navigate(to="/", options = object : NavigateOptions { override var replace: Boolean? = null, override var state:...
  • u

    user

    07/18/2022, 4:41 PM
    Should I use separated Repositories, ViewModels, and Models for Retrofit, and Room database? Should I use separated Model, Repository, and ViewModel for the Retrofit, and Room, while using MVVM?
  • u

    user

    07/18/2022, 4:41 PM
    [Kotlin][Firestore]Turn a list of data objects into a hash map, send it to firestore, retrieve the data and turn it back into a list of objects again Bloody beginner in Kotlin/Android here and trying his best. Problem: I am trying to push a list of data objects into firebase and managed to pull that off with the following function: fun createData(collectionName:String){ //Create Data here val docData: MutableMap = HashMap() docData["data"] = Arrays.asList( JournalEntry("Title 1", 0, 0), JournalEntry("Title 2", 0, 1), JournalEntry("Title 3", 0, 0) ) db.collection(collectionName)...
  • u

    user

    07/18/2022, 5:01 PM
    Conditional navigation start destination in jetpack compose I am using navigation-compose along with bottom bar in jetpack compose. I want to show different bottom bar for different type of user. For that, I need to set conditional startDestination in NavHost. How do i do that? I've tried below but it's not setting startDestination val user by remember { mutableStateOf(viewModel.user) }.collectAsState() var startDestination = Screens.UserType1.route LaunchedEffect(user) { startDestination = if (loggedInUser?.userType == UserType.Seller)...
  • u

    user

    07/18/2022, 5:21 PM
    Why does this web service code not output? I am a beginner Android developer, I wrote this code related to web service, but this program has no output (I am not getting any error). And I'm sure that the API is correct, but it doesn't show anything in the text view.And when the app is running on the device, the internet is on. mainActiviy: class MainActivity : AppCompatActivity() { lateinit var binding : ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding =...
  • u

    user

    07/18/2022, 5:21 PM
    Two results lists merged from room and API I would like to add two results from API into one, but in this case I use local DAO with Room and remoteApi. I have two methods. localRepo.getFirst(elementId) remoteRepo.getSecond(query) usage in viewmodel private val _myLiveData = MediatorLiveData() [...] viewModelScope.launch { _myLiveData.postValueFromApiResponse { localRepo.getFirst(myId) -> LiveData remoteRepo.getSecond"myQuery") -> ApiResponse extensionOfLiveData suspend fun...
  • u

    user

    07/18/2022, 5:21 PM
    Large file parsing speedup The file has 4 million lines. I get each line from the file using BufferedReader. Next, the resulting string is parsed using JSONObject and inserted into the database using room How to get the maximum speed of this process? So i get the string val coroutineScope = CoroutineScope(Dispatchers.IO) coroutineScope.launch { val inputStream: FileInputStream val reader: BufferedReader if (file.exists()) { val...
  • u

    user

    07/18/2022, 5:21 PM
    It there a way to monitor Android system api calls? I want to monitor several system functions like displayMetrics.heightPixel, Build.DISPLAY or access to the Accelerometer/Gyroscope for arbitrary Apps running on the system. The goal is to log those function calls into a file. Is there a way to monitor it, without reimplementing Android? Do any of you know a good approach for that ?
  • u

    user

    07/18/2022, 6:01 PM
    Kotlin multiplatform test error ("Error_0: Fail to fetch") I have a kotlin-multiplatform project that has a kotlinJS client and a JVM backend. I'm creating some integration tests that are supposed to test the API calls from the client. The function is a suspend function with an HttpClient call with a POST method. I'm using kotlinx-coroutines-test, the test looks like this: @OptIn(ExperimentalCoroutinesApi::class) @Test fun testGetSingleResult() = runTest { val result = getSingleResult(TESTED_ID) assertThat(result.ID).isEqualTo(TESTED_ID) } It...
  • u

    user

    07/18/2022, 6:21 PM
    Delete files in Android 11 I am trying to delete files (photos, videos, audio) with the consent of the user. But when I try to bring up a window for the user agreement, I get an error. For some reason my Uri variable doesn't fit My code: if (Build.VERSION.SDK_INT >= 30) { val collection: ArrayList = ArrayList() for (i in 0 until Params.dataListPath.size) { collection.add(Params.dataListPath[i].file.path.toUri()) Log.d(TAG, "onShowDialogConfirmDelete: " +...
  • u

    user

    07/18/2022, 6:41 PM
    Can't cast 'application] as Application class to the ViewModelFactory I'm trying to follow the android codelabs for room. I've faced some issue - I can't cast application while initializing ViewModel in Fragment, why is that? I've copy pasted this code to the MainActivity, and somehow the 'application' were casted (it wasn't red). I've added th Application class to the manifest. Initializing variable in fragment private val mViewModel: MyViewModel viewModels{ MyViewModelFactory((application as MyApplication).repository) Application class MyApplication:...
  • u

    user

    07/18/2022, 6:41 PM
    How to use schedule? I've seen quite a few examples of 'schedule' being used like this: Timer().schedule(1000) { // code to execute after delay } However, when I try to use it like this the function needs me to supply some sort of 'TimerTask' and I haven't seen anything about that. So my question is how do you properly use schedule?
  • u

    user

    07/18/2022, 6:41 PM
    Why wont my action bar text align to the center i'm trying to center my a action bar text. I've linked the text to my styles.XML, and confirmed this works by changing the font color to red. But when i add android:gravity="center_horizontal", it doesnt seem to work. My styles.xml code: @color/colorPrimary @color/colorPrimaryDark @color/colorAccent 15sp italic center_horizontal My mainactivity oncreate event: setSupportActionBar(findViewById(R.id.tlb_roundedtoolbar)) My custom actionbar styling...
  • u

    user

    07/18/2022, 7:01 PM
    ZonedDateTime localized format I want to display ZonedDateTime in format like 11.10.2022 13:30 (GMT+2) / 11.10.2022 01:30 PM (GMT+2) depending on device settings. So far I have done something similar using formatDateTime function from DateUtils class, but this function doesn't display (GMT+2) It takes time in milliseconds as a argument. How can I do this with ZonedDateTime?
  • u

    user

    07/18/2022, 7:21 PM
    How to use EditText TextWatcher in Fragment on Android In my application I want 2 fragments and for show this fragment I used navigation component. First fragment is Home and second fragment is Detail. I have one problem, in fragment Home I have EditText and want when write on EditText show a Toast! But when go from Home to Detail, and then back to Home call EditText automatically!!! My code : searchEdt.textChanges() .skipInitialValue() .debounce(500, TimeUnit.MILLISECONDS)...
Powered by Linen
Title
u

user

07/18/2022, 7:21 PM
How to use EditText TextWatcher in Fragment on Android In my application I want 2 fragments and for show this fragment I used navigation component. First fragment is Home and second fragment is Detail. I have one problem, in fragment Home I have EditText and want when write on EditText show a Toast! But when go from Home to Detail, and then back to Home call EditText automatically!!! My code : searchEdt.textChanges() .skipInitialValue() .debounce(500, TimeUnit.MILLISECONDS)...
View count: 4