在拆分屏幕中以编程方式打开应用 [英] Programmatically open app in split screen

查看:159
本文介绍了在拆分屏幕中以编程方式打开应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在android N(SDK 24)的拆分屏幕中打开另一个应用程序?

How do I open another app in a split screen in the android N (SDK 24)?

在文档中,我发现了这一点:

In the documentation I found this:

在多窗口模式下启动新活动

启动新活动时,可以向系统提示新活动应显示在当前活动附近.为此,请使用标志Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT.传递此标志要求以下行为:

When you launch a new activity, you can hint to the system that the new activity should be displayed adjacent to the current one, if possible. To do this, use the flag Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT. Passing this flag requests the following behaviour:

如果设备处于分屏模式,则系统会尝试在启动该设备的活动旁边创建新活动,因此这两个活动共享屏幕.不能保证系统能够执行此操作,但是如果可能,它将使活动相邻.如果设备未处于分屏模式,则此标志无效.如果设备处于自由格式模式,并且正在启动新活动,则可以通过调用ActivityOptions.setLaunchBounds()来指定新活动的尺寸和屏幕位置.如果设备未处于多窗口模式,则此方法无效.

If the device is in split-screen mode, the system attempts to create the new activity next to the activity that launched it, so the two activities share the screen. The system is not guaranteed to be able to do this, but it makes the activities adjacent if possible. If the device is not in split-screen mode, this flag has no effect. If a device is in freeform mode and you are launching a new activity, you can specify the new activity's dimensions and screen location by calling ActivityOptions.setLaunchBounds(). This method has no effect if the device is not in multi-window mode.

因此,当我尝试此操作时, Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT 标志不存在.我安装了

so when I tried this out, the Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT flag does not exist. I installed

  • Android 6.x(N)SDK 24修订版1
  • Android N预览版SDK N版本3
  • Android 6.0(Marshmallow)SDK 23版本3

这是我的礼物:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "PACKAGENAME"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 2
        versionName "2.4.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'org.jsoup:jsoup:1.8.3'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
}

推荐答案

首先,所有应用都应针对SDK 24+版本.如果目标是低于24的SDK,则分屏模式将不起作用.然后仔细阅读此处

First of all app should be targeted to SDK 24+ version. If it targeted to lower than 24 SDK then split screen mode would not work. Then carefully read here and here

如果设备处于分屏模式,则系统尝试创建在启动该活动的活动旁边的新活动,因此这两个活动活动共享屏幕.系统不保证能够为此,但是如果可能的话,它会使活动相邻.

If the device is in split-screen mode, the system attempts to create the new activity next to the activity that launched it, so the two activities share the screen. The system is not guaranteed to be able to do this, but it makes the activities adjacent if possible.

此标志仅在分屏多窗口模式下使用.新的活动将显示在启动该活动的旁边.这个可以仅与FLAG_ACTIVITY_NEW_TASK结合使用.另外,设定如果您想要一个新的实例,则需要FLAG_ACTIVITY_MULTIPLE_TASK现有的要创建的活动.

This flag is only used in split-screen multi-window mode. The new activity will be displayed adjacent to the one launching it. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK. Also, setting FLAG_ACTIVITY_MULTIPLE_TASK is required if you want a new instance of an existing activity to be created.

这意味着您无法以编程方式启动分屏模式.如果您已经处于分屏模式,则可以尝试在屏幕的另一部分启动活动.

It means that you can't start split screen mode programmatically. You can just try to launch activity in another part of screen if you are already in split screen mode.

这篇关于在拆分屏幕中以编程方式打开应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆