How to enable PictureInPicture for android activities? #12780
-
I am adding
in the main activy at manifest, but when I try to open the PictureInPicture method, I always receive:
But if I create a class in a native module, and launch from native java creating an intent, it works fine. I would like to use it with a titanium window. Somehow it seems as the activity properties are lost when opening a new window. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The main activity is the splash screen window you see on startup. If you're trying to make a Titanium <ti:app>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application>
<activity android:name="org.appcelerator.titanium.TiActivity" android:supportsPictureInPicture="true"/>
</application>
</manifest>
</android>
</ti:app> This means you would need to call the Java Note that I've never tried pictured-in-picture mode before. Titanium doesn't officially support it, but theoretically the above should make it work. |
Beta Was this translation helpful? Give feedback.
-
I tested this out today. I can make picture-in-picture work with a Titanium window in hyperloop, but it'll end up having navigation problems because the system will disconnect the Titanium window/activity from its parent. This completely breaks back navigation. Unfortunately, this is not something I think we can fix or work-around. From looking at Google's docs and stackoverflow, you're expected to make the picture-in-picture window its own standalone singleTask activity running on a separate task (ie: a separate UI stack). So, I think picture-in-picture activity is best implemented natively... but you can launch it from your Titanium app. The below is what I've tested with. <ti:app>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application>
<activity
android:name="org.appcelerator.titanium.TiActivity"
android:supportsPictureInPicture="true"
android:excludeFromRecents="true"
android:noHistory="true"
android:autoRemoveFromRecents="true"
android:allowTaskReparenting="false"/>
</application>
</manifest>
</android>
<modules>
<module>hyperloop</module>
</modules>
</ti:app> // app.js
const Activity = require('android.app.Activity');
const parentWindow = Ti.UI.createWindow();
const button = Ti.UI.createButton({ title: "Show Picture-in-Picture" });
button.addEventListener("click", () => {
if (Ti.Platform.Android.API_LEVEL < 24) {
alert("Picture-in-Picture is only supported on Android 7 and higher.")
return;
}
const childWindow = Ti.UI.createWindow();
childWindow.add(Ti.UI.createLabel({ text: "My PiP Window" }));
childWindow.addEventListener("open", () => {
const currentActivity = new Activity(childWindow.activity);
currentActivity.enterPictureInPictureMode();
});
childWindow.open();
});
parentWindow.add(button);
parentWindow.open(); |
Beta Was this translation helpful? Give feedback.
-
Thanks everybody, it's working cool. |
Beta Was this translation helpful? Give feedback.
The main activity is the splash screen window you see on startup.
If you're trying to make a Titanium
Ti.UI.Window
a picture-in-picture window, then you need to apply this attribute to theorg.appcelerator.titanium.TiActivity
instead. You can do so in the "tiapp.xml" as shown below. (Note that all activities are resizable by default so you don't need to add that attribute.)This means you would need to call the Java
enterP…