Disable presentation hiding (secondary screen)

I am working on a project that is supposed to show a small presentation on an additional display (API 4.2). So far, everything is working fine. But if I close the application, I cannot prevent the presentation from closing. I would like to create an application that launches a background service that initializes the presentation. So that the user simply sees the notification icon in the status bar, but the service transfers the streaming content to the secondary display.

Any ideas if this can be implemented? I tried this with backgroundservice but don't know which context should I use. Tried this with

getApplicationContext() 

but then I get an exception:

 Unable to add window -- token null is not for an application 

If I use a static method like getAppContext() (I know such an ugly hack), it will show the presentation, but also hide it if I close the application.

Any ideas?

+5
android service presentation
source share
2 answers

Create a service that uses Context.createDisplayContext (Display) to get a new window manager for your secondary display - this is how the presentation works

take a look at this link as an example: http://www.java2s.com/Open-Source/Android/android-core/platform-frameworks-base/com/android/server/LoadAverageService.java.htm

In onCreate () instead of getting WindowManagerImpl:

 public void onCreate(){ ... WindowManagerImpl wm = (WindowManagerImpl)getSystemService(WINDOW_SERVICE); wm.addView(mView, params); } 

call a method like this:

 private void addView(WindowManager.LayoutParams params){ DisplayManager dm = (DisplayManager) getApplicationContext().getSystemService(DISPLAY_SERVICE); if (dm != null){ Display dispArray[] = dm.getDisplays(); if (dispArray.length>0){ Context displayContext = getApplicationContext().createDisplayContext(dispArray[1]); WindowManager wm = (WindowManager)displayContext.getSystemService(WINDOW_SERVICE); wm.addView(mView, params); } } } 

Your presentation will be added to the secondary display, and since this is performed by the service, your activity performed on the primary display is not suspended

+7
source share

Any ideas if this can be implemented?

Since Presentation is a subclass of Dialog , your Presentation can only be visible when you have activity that places it in the foreground.


UPDATE

Icarmel's answer works, although it lacks details. I now have a PresentationService in my CWAC-Presentation library that offers a full working implementation of this technique. To answer my question in your comment on icarmel's answer, you use WindowManager.LayoutParams.TYPE_SYSTEM_ALERT in WindowManager.LayoutParams , which in turn requires SYSTEM_ALERT_WINDOW permission (unfortunately).

+5
source share

All Articles