Skip to content

Commit d168091

Browse files
committed
fix screen sharing permission on Samsung
1 parent 3898604 commit d168091

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

android/src/main/java/io/getstream/webrtc/flutter/GetUserMediaImpl.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,40 @@ public static class ScreenRequestPermissionsFragment extends Fragment {
182182

183183
private ResultReceiver resultReceiver = null;
184184
private int requestCode = 0;
185-
private final int resultCode = 0;
185+
private int resultCode = 0;
186+
private boolean hasRequestedPermission = false;
186187

187188
private void checkSelfPermissions(boolean requestPermissions) {
189+
// Avoid requesting permission multiple times
190+
if (hasRequestedPermission) {
191+
return;
192+
}
193+
188194
if (resultCode != Activity.RESULT_OK) {
189195
Activity activity = this.getActivity();
196+
if (activity == null || activity.isFinishing()) {
197+
return;
198+
}
199+
190200
Bundle args = getArguments();
201+
if (args == null) {
202+
return;
203+
}
204+
191205
resultReceiver = args.getParcelable(RESULT_RECEIVER);
192206
requestCode = args.getInt(REQUEST_CODE);
193-
requestStart(activity, requestCode);
207+
208+
hasRequestedPermission = true;
209+
210+
// Post the permission request to allow the activity to fully stabilize.
211+
// This helps prevent the app from going to background on Samsung and other
212+
// devices when the MediaProjection permission dialog appears.
213+
new Handler(Looper.getMainLooper()).postDelayed(() -> {
214+
Activity currentActivity = getActivity();
215+
if (currentActivity != null && !currentActivity.isFinishing() && isAdded()) {
216+
requestStart(currentActivity, requestCode);
217+
}
218+
}, 100);
194219
}
195220
}
196221

0 commit comments

Comments
 (0)