kotlin

Null content Shared Preferences in Kotlin

☆樱花仙子☆ 提交于 2021-01-29 20:26:18
问题 I'm developing an app that uses Shared Preferences, so I created a class only for this, but when I launch the app I get this error: 2020-06-03 14:51:50.124 32656-32656/com.go.experimental E/AndroidRuntime: FATAL EXCEPTION: main Process: com.go.experimental, PID: 32656 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.go.experimental/com.go.experimental.AccesoActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content

Android Kotlin - Volley set POST Parameters in JsonArrayRequest

好久不见. 提交于 2021-01-29 20:21:34
问题 This is the code: val requestQueue: RequestQueue = Volley.newRequestQueue(this@MainActivity) val jsonArrayRequest = JsonArrayRequest( Request.Method.POST, "$domain/do_getmemes.php", null, Response.Listener { response -> }, Response.ErrorListener { // Do something when error occurred } ) requestQueue.add(jsonArrayRequest) and I just want to add some Parameters! I've seen this JAVA example: https://gist.github.com/mstfldmr/f6594b2337e3633673e5 but I don't know what/where/how to add the

Java TLS: Disable SNI on client handshake

白昼怎懂夜的黑 提交于 2021-01-29 19:40:50
问题 I'm trying to create a JVM HTTP client which will not send server_name in the Client Handshake (long story, but I'm simulating a legacy system which doesn't support SNI). Setting the serverNames SSLParameters doesn't do the trick, I can still see the "Server Name Indication extension" in Wireshark. fun run() { val keyStore = keyStore() val trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) trustFactory.init(keyStore) val sslContext = SSLContext

AlarmManager with Notification in Android does not show any notifications

早过忘川 提交于 2021-01-29 19:03:05
问题 I try to create daily notification for my application. In order to test the application I set the interval for the notifications to 15 minutes. Unfortunately, no notification is shown. Neither when the application is running nor when it is closed. I tried to inspire myself with these solutions: https://stackoverflow.com/questions/33055129/how-to-show-a-notification-everyday-at-a-certain-time-even-when-the-app-is-close https://developer.android.com/codelabs/android-training-alarm-manager#0

Sub router cannot be mounted on an exact path

扶醉桌前 提交于 2021-01-29 18:55:53
问题 I would like to do nested routes in vert.x and I have tried the following: class MainVerticle : AbstractVerticle() { private fun apiResource(r: Router): Unit { r.route("/api") .subRouter(GenderResource(vertx).create()) } private fun rootResource(r: Router): Unit { r.route("/").handler { val res = it.response() res.putHeader("content-type", "text/plain"); // Write to the response and end it res.end("I am healthy"); } } override fun start(startPromise: Promise<Void>) { val server = vertx

Android - ShareActionProvider Share Menu add particular option

删除回忆录丶 提交于 2021-01-29 18:55:15
问题 This is what I have: val imgURL = "https://blaaaa.com/pic.jpg" val shareIntent = Intent() shareIntent.action = Intent.ACTION_SEND shareIntent.type = "text/plain" shareIntent.putExtra( Intent.EXTRA_TEXT, context.getString(R.string.check_this_out) + " " + domain + "/post/?id=" + meme.id ) context.startActivity( Intent.createChooser( shareIntent, context.getString(R.string.send_to) ) ) This way I'm sending a text to any available app in the share menu. But I need to add one PARTICULAR option

Cast exception when mocking kotlin lambda callbacks in Mockk

青春壹個敷衍的年華 提交于 2021-01-29 18:54:26
问题 I am having some trouble mocking callback functions with Mockk. I am trying to mock a task success listener that is called like this: collection .add(Item()) .addOnSuccessListener { update(collection.document(it.id)) } Where the java signature for the callback would look like this: public interface OnSuccessListener<T> { void onSuccess(T var1); } and the signature for addOnSuccessListener looks like this public abstract Task<DocumentReference> addOnSuccessListener(@NonNull OnSuccessListener

ImageFile(path, Uri) to Base64 encoded string has problem in Kotlin

你。 提交于 2021-01-29 18:24:06
问题 I tried to capture camera preview in android device and encode imagefiles to Base64 String. I've already tested like this // Convert Failed to Image private fun encoder1(filePath: File): String{ val bytes = filePath.readBytes() val base64 = android.util.Base64.encodeToString(bytes, android.util.Base64.NO_WRAP) return base64 } // Saved Broken Image private fun encoder2(imageUri: Uri): String { val input = this.contentResolver.openInputStream(imageUri) //val bm = BitmapFactory.decodeResource

Coroutines And Firebase: How to Implement Javascript-like Promise.all()

非 Y 不嫁゛ 提交于 2021-01-29 17:36:57
问题 In Javascript, you can start two (or more) asynchronous tasks simultaneously, wait both of them to finish and then do something/continue: const [firstReturn, secondReturn] = await Promise.all([ firstPromise, secondPromise ]; // Do something with first and second return. What I want to do in Kotlin (Android) is to start downloading two images from Firebase and when both downloads are completed - update the UI with them. So I have two Firebase async functions like this: FirebaseStorage

Firebase onNewToken not refreshing my token

夙愿已清 提交于 2021-01-29 17:28:08
问题 So, I need to refresh my token each time it expires, but the service runing behind ddoes not trigger onNewToken() Manifest <service android:name=".fcm.MyFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> Code class MyFirebaseMessagingService: FirebaseMessagingService() { override fun onNewToken(token: String) { super.onNewToken(token) val currentUser = FirebaseAuth.getInstance()