|
@@ -44,14 +44,26 @@ public class PictureInPictureModule extends ReactContextBaseJavaModule {
|
44
|
44
|
PictureInPictureParams.Builder builder
|
45
|
45
|
= new PictureInPictureParams.Builder()
|
46
|
46
|
.setAspectRatio(new Rational(1, 1));
|
47
|
|
- boolean r
|
48
|
|
- = currentActivity.enterPictureInPictureMode(builder.build());
|
|
47
|
+ Throwable error;
|
49
|
48
|
|
50
|
|
- if (r) {
|
|
49
|
+ // https://developer.android.com/reference/android/app/Activity.html#enterPictureInPictureMode(android.app.PictureInPictureParams)
|
|
50
|
+ //
|
|
51
|
+ // The system may disallow entering picture-in-picture in various
|
|
52
|
+ // cases, including when the activity is not visible, if the screen
|
|
53
|
+ // is locked or if the user has an activity pinned.
|
|
54
|
+ try {
|
|
55
|
+ error
|
|
56
|
+ = currentActivity.enterPictureInPictureMode(builder.build())
|
|
57
|
+ ? null
|
|
58
|
+ : new Exception("Failed to enter Picture-in-Picture");
|
|
59
|
+ } catch (RuntimeException re) {
|
|
60
|
+ error = re;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ if (error == null) {
|
51
|
64
|
promise.resolve(null);
|
52
|
65
|
} else {
|
53
|
|
- promise.reject(
|
54
|
|
- new Exception("Failed to enter Picture-in-Picture"));
|
|
66
|
+ promise.reject(error);
|
55
|
67
|
}
|
56
|
68
|
|
57
|
69
|
return;
|