Reputation: 6958
I'm trying to display (as a system-level application) multiple activities. There's an hidden AOSP class called ActivityView
meant to do just that. Here's how you would use it, as far as I understand:
findViewById(R.id.view1).setCallback(object: ActivityView.StateCallback() {
override fun onActivityViewReady(view: ActivityView?) {
view?.startActivity(InnerActivity.getIntent(view.context, "my extra"))
}
override fun onActivityViewDestroyed(view: ActivityView?) {
// Cleanup
}
})
Note that the inner activity has to be declared with the attribute allowEmbedded
set to true. It is in my case. My application also has the permission android.permission.INJECT_EVENTS
(and is built as a system application, with the ROM certificate and installed in /system/priv-app
)
Now, for the problem: when I call startActivity
, the inner activity is displayed as a new activity on the stack, like any standard Context.startActivity
call would do (the ActivityView.startActivity
method actually does exactly that, but adds some options to the bundle before that, to display the activity on a virtual display). I also have a system Toast displayed that tells me that my App does not support launch on secondary displays
.
In regard to this Toast, I tried giving my application the android.permission.CAPTURE_SECURE_VIDEO_OUTPUT
permission, to no help.
I'm probably missing something related to the virtual display, but I can't see what…
(I know ActivityView
is hidden, and that actually could be a bug, I'm just being curious of what it can or cannot do.)
Upvotes: 3
Views: 7780
Reputation: 1073
In my case I was using Flutter and its PlatformView API to display ActivityView as a widget. Unfortunately, both ActivityView and PlatformView are using virtual displays as the underlaying technology, and maybe it's not possible to show one virtual display inside another.
Upvotes: 0
Reputation: 703
I have already used ActivityView successfully on Android 9 (Pie). I noted some key points that you can refer to use ActivityView.
The application which use ActivityView need to be private application (installed in /system/priv-app) and must use system uid (declare in AndroidManifest.xml) as below
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.packagename" android:sharedUserId="android.uid.system">
Noted that you need to replace "your.packagename" by package name of your application
You need config Android framework to support secondary display by copy file android.software.activities_on_secondary_displays.xml to /system/etc/permissions/
<?xml version="1.0" encoding="utf-8"?> <permissions> <feature name="android.software.activities_on_secondary_displays" /> </permissions>
Enable resizeable mode and using singleTask for the Activity need to be placed inside an ActivityView
In AndroidManifest.xml
<activity android:name=".YourActivity" android:resizeableActivity="true" android:launchMode="singleTask">
Upvotes: 4
Reputation: 30990
You must add these two attributes to the Activity tag in your manifest for any activity which should be allowed to be placed inside an ActivityView:
android:resizeableActivity="true"
android:allowEmbedded="true"
As you know, this is not documented, since ActivityView is not part of the Android SDK.
Upvotes: 0