java.lang.IllegalStateException: enterPictureInPictureMode:



错误消息

java.lang.IllegalStateException: enterPictureInPictureMode: Current activity does not support picture-in-picture.
at android.os.Parcel.createException(Parcel.java:2079)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at android.app.IActivityTaskManager$Stub$Proxy.enterPictureInPictureMode(IActivityTaskManager.java:6824)
at android.app.Activity.enterPictureInPictureMode(Activity.java:2728)
at com.MapActivity.enterPIP(apActivity.java:2892)
at com.MapActivity.onUserLeaveHint(MapActivity.java:2915)
at android.app.Activity.performUserLeaving(Activity.java:8015)
at android.app.Instrumentation.callActivityOnUserLeaving(Instrumentation.java:1517)
at android.app.ActivityThread.performUserLeavingActivity(ActivityThread.java:4417)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4402)
at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:46)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.wm.ActivityTaskManagerService.ensureValidPictureInPictureActivityParamsLocked(ActivityTaskManagerService.java:4263)
at com.android.server.wm.ActivityTaskManagerService.enterPictureInPictureMode(ActivityTaskManagerService.java:4140)
at android.app.IActivityTaskManager$Stub.onTransact(IActivityTaskManager.java:3262)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)

我的设置值和代码。

AndroidManifest.xml

...
android:name="com.test.MapActivity"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
android:configChanges="orientation|smallestScreenSize|screenLayout|screenSize"
android:exported="true"
...

地图活动.java

public void enterPIP(){
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(new Rational(width, height)).build();
...
boolean supportsPIP =
packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
if (supportsPIP) {
Log.d("PIP", "*** Picture-in-Picture ***");
enterPictureInPictureMode(params);
} else {
Log.d("PIP", "*** No support Picture-in-Picture ***");
}
}
}

调用输入图片后APP崩溃(参数(;

它适用于具有简单按钮的活动,但在由复杂元素组成的 MapActivity 中不起作用。

终于,我发现了问题所在! 另一个活动扩展了此 MapActivity。我在AndroidManifest中为此活动声明了PIP配置,它可以工作。:D

不要忘记通过将android:supportsPictureInPicture 设置为 true 来在清单中注册您的视频活动:

<activity android:name="VideoActivity"
android:supportsPictureInPicture="true"

默认情况下,系统不会自动支持应用程序的画中画。如果您希望在应用中支持 PiP,请将android:supportsPictureInPicture设置为true在清单中注册视频活动。此外,指定您的活动处理布局配置更改,以便在 PiP 模式转换期间发生布局更改时您的活动不会重新启动。

<activity android:name="VideoActivity"
android:supportsPictureInPicture="true"
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"/>

相关内容

  • 没有找到相关文章

最新更新