提交 6709e6c4 authored 作者: kongdywang's avatar kongdywang

fix the problem that Android Picture-in-Picture cannot launch applications on some systems

上级 d09b4b6f
......@@ -20,6 +20,7 @@
<action android:name="com.tencent.flutter.startPip"/>
<action android:name="com.tencent.flutter.exitPip"/>
<action android:name="com.tencent.flutter.updatePip"/>
<action android:name="com.tencent.flutter.doExitPip"/>
</intent-filter>
</activity>
......
......@@ -133,6 +133,7 @@ public class FTXEvent {
// 画中画界面恢复,即点击放大按钮
public static final int EVENT_PIP_MODE_RESTORE_UI = 5;
public static final String PIP_ACTION_DO_EXIT = "com.tencent.flutter.doExitPip";
// Start PIP.
// 启动画中画
public static final String PIP_ACTION_START = "com.tencent.flutter.startPip";
......
......@@ -340,6 +340,14 @@ public class FlutterPipImplActivity extends Activity implements TextureView.Surf
PipParams pipParams = data.getParcelable(FTXEvent.EXTRA_NAME_PARAMS);
updatePip(pipParams);
}
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_DO_EXIT)) {
overridePendingTransition(0, 0);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
FlutterPipImplActivity.this.finishAndRemoveTask();
} else {
FlutterPipImplActivity.this.finish();
}
mIsPipFinishing = false;
} else {
LiteavLog.e(TAG, "unknown pip action:" + action);
}
......@@ -355,17 +363,17 @@ public class FlutterPipImplActivity extends Activity implements TextureView.Surf
}
}
/**
* move task to from。Prevent the issue of picture-in-picture windows failing to launch the app in certain cases.
*/
public void movePreActToFront() {
if (VERSION.SDK_INT == VERSION_CODES.Q) {
Activity activity = TXFlutterEngineHolder.getInstance().getPreActivity();
if (null != activity) {
Intent intent = new Intent(FlutterPipImplActivity.this, activity.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
Activity activity = TXFlutterEngineHolder.getInstance().getPreActivity();
if (null != activity) {
Intent intent = new Intent(FlutterPipImplActivity.this, activity.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
......@@ -373,15 +381,16 @@ public class FlutterPipImplActivity extends Activity implements TextureView.Surf
* move task to from。Prevent the issue of picture-in-picture windows failing to launch the app in certain cases.
*/
public void moveCurActToFront() {
mPipContainer.postDelayed(new Runnable() {
mPipContainer.post(new Runnable() {
@Override
public void run() {
Activity activity = FlutterPipImplActivity.this;
Intent intent = new Intent(FlutterPipImplActivity.this, activity.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setAction(FTXEvent.PIP_ACTION_DO_EXIT);
startActivity(intent);
}
}, 2000);
});
}
/**
......@@ -408,16 +417,23 @@ public class FlutterPipImplActivity extends Activity implements TextureView.Surf
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
/*
The PiP window can launch its own Activity. Therefore,
we can initiate our own here. By executing the termination code during the launch,
we can bring our own Activity back to the original AppTask and launch the original app.
Subsequently, when we end the Picture-in-Picture page,
it can display back to the original page.
*/
moveCurActToFront();
overridePendingTransition(0, 0);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
FlutterPipImplActivity.this.finishAndRemoveTask();
} else {
finish();
FlutterPipImplActivity.this.finish();
}
mIsPipFinishing = false;
movePreActToFront();
}
}, 600);
}, 800);
} else {
overridePendingTransition(0, 0);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论