kotlin

Android - Ipay88 got error Access denied finding property “ro.serialno”

你离开我真会死。 提交于 2021-02-05 08:10:28
问题 hello i tried to implement IPayPayment on Android, val checkoutIntent = Ipay.getInstance().checkout(payment,applicationContext, ResultDelegate()) checkoutIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK startActivity(checkoutIntent) but i got error libc: Access denied finding property "ro.serialno" any solution? 回答1: The error is thrown on Android 9 devices. when we try to access Serial number of device, without application having READ_PHONE_STATE permission. The error is thrown when serial

kotlin Converts bytearray to String data crash

纵饮孤独 提交于 2021-02-05 08:08:47
问题 Converts bytearray data received through communication into String. If the byte array is long (ex 355), the end is truncated. Same goes for utf-8, utf-16 etc. fun getString(content:ByteArray, length: Int): String? { var str: String? = null try { str = String(content, 0, length, Charset.forName("euc-kr")) i("Test::getString str : " + str) } catch (e: java.lang.Exception) { i("Test::getString ERR ") error("Charset exception", DlgAprList::class.java) } return str } Occurs when it exceeds 355

Why do I need a parameter in a primary constructor without val/var modifier in Kotlin?

為{幸葍}努か 提交于 2021-02-05 06:40:29
问题 If I create a class, I can pass a parameter: class Person(name: String) { } I also can write the same, but with val and then I'll be able to use properties to get this value, when I created an object. val person = Person("Name") person.name The question is: why do I need just a parameter without the val? Where, how and why should I use it? 回答1: If you use var or val in the constructor, you are declaring properties and initializing them directly. If you don't, those parameters are used for

How to perform companion object lateinit is initiallize check

纵然是瞬间 提交于 2021-02-05 06:15:07
问题 If I have a lateinit variable, I could check is it initialized using (this::lateInitVar.isInitialized), as shown in https://stackoverflow.com/a/47860466/3286489 However if the variable is a companion object, how could I do so? e.g. class MyClass { companion object { lateinit var myGlobalLateInit: String } lateinit var myLocalLateInit: String fun settingVariable() { if (!this::myLocalLateInit.isInitialized) { myLocalLateInit = "I am set" } if (!MyClass::myGloablLateInit.isInitialized) { //

lateinit property data has not been initialized

老子叫甜甜 提交于 2021-02-05 05:57:26
问题 Gson Convertable data is not set in Recyclerview using Retrofit2 and rxjava2 then subscribe throughble its Give Error: UninitializedPropertyAccessException: lateinit property data has not been initialized JSON data parsing by retrofit2 and rxjava2. when parsing GSON Data Converting GSon, rxjava2 Subscribe the data then give lateinit property error and its not set in recyclerview. MainActivity.kt class Company : AppCompatActivity() { internal lateinit var api : APIInterface var

How to find the whole word in kotlin using regex

余生长醉 提交于 2021-02-04 19:24:07
问题 I want to find the whole word in string. But I don't know how to find the all word in kotlin. My finding word is [non alpha]cba[non alpha]. My example code is bellows. val testLink3 = """cba@cba cba""" val word = "cba" val matcher = "\\b[^a-zA-Z]*(?i)$word[^a-zA-Z]*\\b".toRegex() val ret = matcher.find(testLink3)?.groupValues But output of my source code is "cba" My expected value is string array such as "{cba, cba, cba}". How to find this value in kotlin language. 回答1: You may use val

Android Firebase : Update/Add record in Nested Array data

泄露秘密 提交于 2021-02-04 19:10:30
问题 I am stuck in one case of firebase operation in android. My Requirement : I have table Named : "Values" This value table contains following type of data. { "menu": [ { "category": "cocktails", "product": [ { "id": "123", "name": "test1" }, { "id": "456", "name": "test2" } ] }, { "category": "vodka", "product": [ { "id": "789", "name": "test3" }, { "id": "901", "name": "test4" } ] } ] } Now, I want to update id : 123 with name = "test5" , How to update this nested array object in firebase

Method reference to property setter

余生长醉 提交于 2021-02-04 18:59:26
问题 How could I get method reference to property setter without using kotlin-reflect? Basically, if I'll write my code in java way it's super simple fun setValue(i: Int) = Unit val a: (Int) -> Unit = this::setValue But for var value: Int I'm getting var value = 1 val a: KMutableProperty0<Int> = this::value 回答1: this::value is a property reference. It returns a KMutableProperty . To get the setter you will need the setter field of KMutableProperty . So you will need this: class C { var field: Int

Interface's function clashes with Property's getter

老子叫甜甜 提交于 2021-02-04 12:53:13
问题 An interface's function name clashes with a property's getter name intentionally, but it's prohibited by the compiler because of accidental override problem. Is it possible to instruct the compiler this is intentional? interface A { fun getFoo() } class B: A { val foo } 回答1: This feature seems not to be implemented in any way. @AndreyBreslav's comment on a similar question: You can not override Java methods with Kotlin properties at the moment. It would be nice if we could support it, but we

kotlinx.android.synthetic unused android studio issue

和自甴很熟 提交于 2021-02-04 11:12:09
问题 I am working one project using kotlin + Rxjava + MVVM. During development facing issue of importing view ids in Fragment or viewholder. import kotlinx.android.synthetic.main.layout.* unused with kotlin. Normaly view id should used from kotlin synthetic layout imports but it directly import it from R.id that should not happen. Kotlin plugin version : org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.40 My gradle file : apply plugin: 'com.android.feature' apply plugin: 'kotlin-android' apply plugin