kotlin

How to check Google Mobile Services enable in device or not?

无人久伴 提交于 2021-02-11 04:26:41
问题 I have to check if google services are active on the device. How can I check it? Looking just play services is enough? I need this check for Huawei services. 回答1: final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (status != ConnectionResult.SUCCESS) { Log.e(TAG, GooglePlayServicesUtil.getErrorString(status)); return false; } else { Log.i(TAG, GooglePlayServicesUtil.getErrorString(status)); return true; } 回答2: I think this code will help you final int status =

Capture layout screen in Android

两盒软妹~` 提交于 2021-02-11 01:55:13
问题 I am facing an issue. I want to capture screen of a XML layout. I know there is a lot of topic on this question. I read them all. But No one of them helped me. Note : I want to get screen capture of a layout wich is not part of the current activity this my function which is suppose to make capture of the Y layout (called on X activity) fun getTestCapture() : Bitmap{ val view = layoutInflater.inflate(R.layout.activity_test, null) val layout = view.findViewById<LinearLayout>(R.id.linearLayout)

Kotlin how to Map JSONArray to Type (Stream)

六月ゝ 毕业季﹏ 提交于 2021-02-10 23:46:45
问题 I'm trying to map my JSONArray to a Array<String?> . I'm doing it like this: fun getTextResponse(responseJson: JSONObject): Array<String?>{ val resultData = responseJson.getJSONArray("data") .getJSONObject(0) .getJSONArray("result") return resultData.map{ it.getString("label") }.toTypedArray() } But it is not typed as a JSONObject , is there any way I can force type it to JSONObject ? 回答1: The problem is that resultData has a type of JSONArray , which is a JSON utility class that doesn't

Kotlin how to Map JSONArray to Type (Stream)

核能气质少年 提交于 2021-02-10 23:45:26
问题 I'm trying to map my JSONArray to a Array<String?> . I'm doing it like this: fun getTextResponse(responseJson: JSONObject): Array<String?>{ val resultData = responseJson.getJSONArray("data") .getJSONObject(0) .getJSONArray("result") return resultData.map{ it.getString("label") }.toTypedArray() } But it is not typed as a JSONObject , is there any way I can force type it to JSONObject ? 回答1: The problem is that resultData has a type of JSONArray , which is a JSON utility class that doesn't

SQL like joins in Firestore

喜夏-厌秋 提交于 2021-02-10 22:41:06
问题 I have a collection called creditcards and a collection called ownedcreditcards in Cloud Firestore. I want to perform a query where I JOIN the two collections to find only the creditcards that exists in the creditcards -collection, and not in the ownedcreditcards . From my understanding SQL like JOINS does not exist in Firestore, and you have to retrieve the data in multiple queries. I am trying to call the getAll() -functions (which retrieves all the documents) on both my collections,

Kotlin: Merge Multiple Lists then ordering Interleaved merge list

 ̄綄美尐妖づ 提交于 2021-02-10 18:31:02
问题 I have class CatalogProduct(id: String, name: String) to declare a product I have two list below: val newestCatalogProductList = mutableListOf<CatalogProduct>() newestCatalogProductList.add(CatalogProduct("A1", "Apple")) newestCatalogProductList.add(CatalogProduct("A2", "Banana")) newestCatalogProductList.add(CatalogProduct("A3", "Orange")) newestCatalogProductList.add(CatalogProduct("A4", "Pineapple")) val popularCatalogProductList = mutableListOf<CatalogProduct>() popularCatalogProductList

IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off

好久不见. 提交于 2021-02-10 17:58:07
问题 I enjoy using the REPL in intelliJ for coding problems like you would find on codesignal. I currently have the version: IntelliJ IDEA 2019.1.3 (Ultimate Edition) Build #IU-191.7479.19, built on May 27, 2019 JRE: 1.8.0_202-release-1483-b58 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.14.4 I have always been really confused by the fact that when running any of these scratch files, the first 5-9 lines I am trying to print output to will just, not exist. Below is an example

IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off

拈花ヽ惹草 提交于 2021-02-10 17:54:16
问题 I enjoy using the REPL in intelliJ for coding problems like you would find on codesignal. I currently have the version: IntelliJ IDEA 2019.1.3 (Ultimate Edition) Build #IU-191.7479.19, built on May 27, 2019 JRE: 1.8.0_202-release-1483-b58 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.14.4 I have always been really confused by the fact that when running any of these scratch files, the first 5-9 lines I am trying to print output to will just, not exist. Below is an example

Parse 2D Array in Kotlin

南楼画角 提交于 2021-02-10 17:30:15
问题 I have created a 2D array named squareData as shown below: private lateinit var squareData: Array<Array<String>> squareData = Array(3, {Array(3, {""})}) Also, I initialized this array with some random values. Now I want to fetch this values one by one. How can I do it using for or forEachIndexed loop? 回答1: You can iterate in the array like this : for (strings in squareData) { for (string in strings) { Your code here } } The first for iterate through the first dimension so it has string arrays

Android webview custom font using javascript

社会主义新天地 提交于 2021-02-10 16:20:49
问题 I am trying to show text in webview with custom font which i have selected to show that font style. So following details explain the problem in code public void setFontFamily(String fontFamily) { exec("javascript:RE.setFontFamily('" + fontFamily + "');"); } So In JS file I have following the code RE.setFontFamily = function(fontFamily) { RE.restorerange(); //document.execCommand("insertHtml", false, "&nbsp") console.log("Font Family: "+fontFamily) document.execCommand("styleWithCSS", null,