From ff146ad58f833fef4298b96bdd75517ae5235690 Mon Sep 17 00:00:00 2001 From: Konstantin Antipochkin Date: Wed, 24 Sep 2025 18:09:41 -0400 Subject: [PATCH 1/3] Eliminated the play store 35+ window.setStatusBarColor warning --- .../android/optimobile/InAppMessageView.java | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java b/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java index 2269231f..f7cd8fbb 100644 --- a/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java +++ b/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java @@ -36,7 +36,6 @@ import androidx.annotation.AnyThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.annotation.UiThread; import com.optimove.android.BuildConfig; @@ -161,27 +160,46 @@ private void sendToClient(String type, JSONObject data) { String script = "window.postHostMessage(" + j.toString() + ")"; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - wv.evaluateJavascript(script, null); - } else { - wv.loadUrl("javascript:" + script); + wv.evaluateJavascript(script, null); + } + + private static boolean isLegacyStatusBarColorSupported() { + return Build.VERSION.SDK_INT < 35; + } + + private static int getStatusBarColorLegacy(Window window) { + if (!isLegacyStatusBarColorSupported() || window == null) { + return 0; } + try { + java.lang.reflect.Method method = Window.class.getMethod("getStatusBarColor"); + Object result = method.invoke(window); + if (result instanceof Integer) { + return (Integer) result; + } + } catch (Throwable ignored) {} + return 0; } - @UiThread - @SuppressWarnings("deprecation") - private void setStatusBarColorForDialog(Activity currentActivity) { - if (currentActivity == null) { + private static void setStatusBarColorLegacy(Window window, int color) { + if (!isLegacyStatusBarColorSupported() || window == null) { return; } + try { + java.lang.reflect.Method method = Window.class.getMethod("setStatusBarColor", int.class); + method.invoke(window, color); + } catch (Throwable ignored) {} + } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + @UiThread + private void setStatusBarColorForDialog(Activity currentActivity) { + if (currentActivity == null) { return; } Window window = currentActivity.getWindow(); - prevStatusBarColor = window.getStatusBarColor(); + prevStatusBarColor = getStatusBarColorLegacy(window); int flags = window.getAttributes().flags; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { @@ -198,18 +216,17 @@ private void setStatusBarColorForDialog(Activity currentActivity) { statusBarColor = currentActivity.getResources().getColor(R.color.statusBarColorForNotch); } - window.setStatusBarColor(statusBarColor); + setStatusBarColorLegacy(window, statusBarColor); } @UiThread - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void unsetStatusBarColorForDialog(Activity dialogActivity) { if (dialogActivity == null) { return; } Window window = dialogActivity.getWindow(); - window.setStatusBarColor(prevStatusBarColor); + setStatusBarColorLegacy(window, prevStatusBarColor); if (prevFlagTranslucentStatus) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); @@ -225,7 +242,7 @@ private void closeDialog(Activity dialogActivity) { if (dialog != null) { dialog.setOnKeyListener(null); dialog.dismiss(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT < 35) { unsetStatusBarColorForDialog(dialogActivity); } } @@ -243,7 +260,7 @@ private void closeDialog(Activity dialogActivity) { @UiThread private void showWebView(@NonNull final Activity currentActivity) { try { - if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } @@ -286,9 +303,7 @@ private void showWebView(@NonNull final Activity currentActivity) { WebSettings settings = wv.getSettings(); settings.setJavaScriptEnabled(true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - settings.setMediaPlaybackRequiresUserGesture(false); - } + settings.setMediaPlaybackRequiresUserGesture(false); wv.addJavascriptInterface(this, JS_NAME); wv.setWebViewClient(this); @@ -315,7 +330,10 @@ private void closeCurrentMessage() { @Override public void onPageFinished(WebView view, String url) { view.setBackgroundColor(android.graphics.Color.TRANSPARENT); - setStatusBarColorForDialog(currentActivity); + if (Build.VERSION.SDK_INT < 35) { + setStatusBarColorForDialog(currentActivity); + } + pageFinished = true; sendCurrentMessageToClient(); @@ -324,7 +342,6 @@ public void onPageFinished(WebView view, String url) { } @Override - @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { super.onReceivedHttpError(view, request, errorResponse); @@ -458,7 +475,7 @@ private void maybeSetNotchInsets(Context context) { } List cutoutBoundingRectangles = displayCutout.getBoundingRects(); - if (cutoutBoundingRectangles.size() == 0) { + if (cutoutBoundingRectangles.isEmpty()) { return; } From 2bdd79ffe2c909ab81a7f8410a456af1ece41d97 Mon Sep 17 00:00:00 2001 From: Konstantin Antipochkin Date: Wed, 24 Sep 2025 18:19:07 -0400 Subject: [PATCH 2/3] Updated version to 7.7.1 --- CHANGELOG.md | 4 ++++ OptimoveSDK/gradle.properties | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67f5930..947726b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.7.1 + +- Use reflective status bar color on pre‑Android 15 (API <35) to avoid Play deprecation warnings + ## 7.7.0 - Updated to use Embedded Messaging V2 endpoints diff --git a/OptimoveSDK/gradle.properties b/OptimoveSDK/gradle.properties index f17fb69d..a8fb9857 100644 --- a/OptimoveSDK/gradle.properties +++ b/OptimoveSDK/gradle.properties @@ -8,8 +8,8 @@ # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m -sdk_version=7.7.0 -sdk_version_code=70700 +sdk_version=7.7.1 +sdk_version_code=70701 sdk_platform=Android android.useAndroidX=true android.enableJetifier=true \ No newline at end of file From d37475f49870a875615a7eff71401461e6eca439 Mon Sep 17 00:00:00 2001 From: Konstantin Antipochkin <51291769+k-antipochkin@users.noreply.github.com> Date: Wed, 24 Sep 2025 18:28:52 -0400 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: baz-reviewer[bot] <174234987+baz-reviewer[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 947726b7..783f528d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 7.7.1 -- Use reflective status bar color on pre‑Android 15 (API <35) to avoid Play deprecation warnings +- Use reflective status bar color on pre-Android 15 (API <35) to avoid Play deprecation warnings ## 7.7.0