Skip to content

Commit

Permalink
fix(share): Address Android 14 changes (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Nov 1, 2023
1 parent 69900c8 commit f5ca8e0
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f5ca8e0

Please sign in to comment.