From 720e83e1df516d95e665ee4fd8354d0bb8b4ad1a Mon Sep 17 00:00:00 2001 From: Andy Valdez Date: Fri, 2 Feb 2024 18:24:36 -0500 Subject: [PATCH] [Fix] Adds export behavior on broadcastreceiver to avoid SDK 34 crash. --- .../ui/reader/ReaderPostDetailFragment.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt index 5c48b3900cfc..53bf0c38a6c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.app.DownloadManager import android.content.Context +import android.content.ContextWrapper import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager @@ -11,6 +12,7 @@ import android.content.res.Resources import android.graphics.Rect import android.graphics.drawable.Drawable import android.net.Uri +import android.os.Build import android.os.Bundle import android.os.Parcelable import android.view.Gravity @@ -1160,10 +1162,18 @@ class ReaderPostDetailFragment : ViewPagerFragment(), super.onStart() dispatcher.register(this) EventBus.getDefault().register(this) - activity?.registerReceiver( - readerFileDownloadManager, - IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) - ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity?.registerReceiver( + readerFileDownloadManager, + IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), + ContextWrapper.RECEIVER_NOT_EXPORTED + ) + } else { + activity?.registerReceiver( + readerFileDownloadManager, + IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) + ) + } } override fun onStop() {