演示模式Android

时间:2016-10-29 19:35:13

标签: java android android-layout android-fragments

我正在尝试使用Android的演示模式创建一个应用程序,以便在我的设备上通过HDMI连接的辅助显示器上传输视频。 我在辅助显示器上运行了一个简单的布局,我能够做到这一点..但是当我启动我的应用程序时它阻止了我在主屏幕上的活动,除了杀死应用程序我什么也做不了。

我在互联网上找到了这个代码。这是一个简单的代码,它在我的辅助屏幕上正确地抛出“R.layout.presentation_with_media_router_content”但我在主屏幕上根本无法做任何事情,直到我从adb中杀死这个应用程序。

我的两个屏幕都通过HDMI(HDMI 1和HDMI 2)连接。在辅助节点上运行演示模式时如何启用主显示屏的任何帮助都会有所帮助。顺便说一句,我正在使用Android N进行此项开发。

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);

    }
}

谢谢,萨蒂什

1 个答案:

答案 0 :(得分:0)

这是我在辅助显示屏上启动Presentation时使用的代码。该方法从onResume调用,并且完美无缺。

@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();
        }
     }
}

您是否尝试过N以外的Android版本?我在4.4和6.0上运行了我的代码