diff --git a/share/android/src/main/java/com/capacitorjs/plugins/share/SharePlugin.java b/share/android/src/main/java/com/capacitorjs/plugins/share/SharePlugin.java index 63b3635d4..36171b7e6 100644 --- a/share/android/src/main/java/com/capacitorjs/plugins/share/SharePlugin.java +++ b/share/android/src/main/java/com/capacitorjs/plugins/share/SharePlugin.java @@ -7,6 +7,7 @@ import android.os.Build; import android.webkit.MimeTypeMap; import androidx.activity.result.ActivityResult; +import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; @@ -41,7 +42,12 @@ public void onReceive(Context context, Intent intent) { } } }; - getActivity().registerReceiver(broadcastReceiver, new IntentFilter(Intent.EXTRA_CHOSEN_COMPONENT)); + ContextCompat.registerReceiver( + getContext(), + broadcastReceiver, + new IntentFilter(Intent.EXTRA_CHOSEN_COMPONENT), + ContextCompat.RECEIVER_EXPORTED + ); } @SuppressWarnings("deprecation") @@ -113,9 +119,12 @@ public void share(PluginCall call) { shareFiles(files, intent, call); } int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { flags = flags | PendingIntent.FLAG_MUTABLE; } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + flags = flags | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT; + } // requestCode parameter is not used. Providing 0 PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, new Intent(Intent.EXTRA_CHOSEN_COMPONENT), flags);