I'm trying to create an App to stream a video on my secondary display connected via HDMI on my device using Android's Presentation mode. I ran a simple Layout on Secondary display and I was able to do that.. But when I launch my app It blocks my Activity on Primary screen and I can't do anything except killing the app.
I found this code somewhere on Internet. It is simple code and it throws "R.layout.presentation_with_media_router_content" on my secondary screen properly but I can't do anything on my primary screen at all until I kill this app from adb.
Both of my screen is connected through HDMI (HDMI 1 & HDMI 2). Any help on how to enable my Primary display while running presentation mode on secondary will help. Btw I'm using Android N for this development.
public class MainActivity extends AppCompatActivity {
ImageButton sendtoback;
private PresentationActivity presentationActivity;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// init Presentation Class
DisplayManager displayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (presentationDisplays.length > 0) {
// If there is more than one suitable presentation display, then we could consider
// giving the user a choice. For this example, we simply choose the first display
// which is the one the system recommends as the preferred presentation display.
Display display = presentationDisplays[0];
PresentationActivity presentation = new PresentationActivity(this, display);
presentation.show();
this.presentationActivity = presentation;
}
}
public void changeText (String s) {
this.presentationActivity.setText(s);
}
public void SendOnBack(View view){
Log.i("VideoApp","StartVideoApp");
}
}
class PresentationActivity extends Presentation {
private TextView text;
private PresentationActivity presentation;
public PresentationActivity(Context outerContext, Display display) {
super(outerContext, display);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.presentation_with_media_router_content);
TextView text = (TextView) findViewById(R.id.textView1);
this.text = text;
text.setText("test");
}
public void setText(String s) {
this.text.setText(s);
}
}
Thanks, Satish
This is the code I use to start the Presentation
on the secondary display. The method is called from onResume
, and it works flawlessly.
@TargetApi(Build.VERSION_CODES.KITKAT)
private void doDisplay() {
DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();
MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
if (displays.length > 1) {
Display presentationDisplay = route.getPresentationDisplay();
if (presentationDisplay != null) {
presentation = new MyPresentation(MainActivity.this, presentationDisplay);
presentation.setAppListener(this);
presentation.show();
}
}
}
Did you try on a version of Android other than N? I have run my code on 4.4 and 6.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.