From aa60a59efc442711ce20a28c6e20ee2dfae6d2be Mon Sep 17 00:00:00 2001 From: ximxim <40807667+lazerblasters@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:09:05 -0400 Subject: [PATCH] fix: added sdk check for android to avoid crash on lower versions --- .../FeedbackReporterModule.kt | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/com/reactnativefeedbackreporter/FeedbackReporterModule.kt b/android/src/main/java/com/reactnativefeedbackreporter/FeedbackReporterModule.kt index 7d62fc6..b578c06 100644 --- a/android/src/main/java/com/reactnativefeedbackreporter/FeedbackReporterModule.kt +++ b/android/src/main/java/com/reactnativefeedbackreporter/FeedbackReporterModule.kt @@ -8,6 +8,7 @@ import android.graphics.Bitmap import android.graphics.Point import android.media.MediaMetadataRetriever import android.net.Uri +import android.os.Build import android.util.Base64 import android.util.Log import android.util.SparseArray @@ -355,29 +356,37 @@ class FeedbackReporterModule(val reactContext: ReactApplicationContext) : ReactC @ReactMethod fun setValue(key: String, value: String, promise: Promise) { - val storage = RNFRStorage(reactContext); - val result = storage.setValue(key, value); - val code = result.getInt("code"); - val error = result.getString("error"); - - if (code == 200) { - promise.resolve(result); + if (Build.VERSION.SDK_INT >= 23) { + val storage = RNFRStorage(reactContext); + val result = storage.setValue(key, value); + val code = result.getInt("code"); + val error = result.getString("error"); + + if (code == 200) { + promise.resolve(result); + } else { + promise.reject(null, error); + } } else { - promise.reject(null, error); + promise.reject(null, "unsupported function below SDK 23"); } } @ReactMethod fun getValue(key: String, promise: Promise) { - val storage = RNFRStorage(reactContext); - val result = storage.getValue(key); - val code = result.getInt("code"); - val error = result.getString("error"); - - if (code == 200) { - promise.resolve(result); + if (Build.VERSION.SDK_INT >= 23) { + val storage = RNFRStorage(reactContext); + val result = storage.getValue(key); + val code = result.getInt("code"); + val error = result.getString("error"); + + if (code == 200) { + promise.resolve(result); + } else { + promise.reject(null, error); + } } else { - promise.reject(null, error); + promise.reject(null, "unsupported function below SDK 23"); } }