错误信息
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"
...
MapActivity.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调用enterPictureInPictureMode(params)后崩溃;
它适用于带有简单按钮的活动,但不适用于由复杂元素组成的 MapActivity。