1

当我将手机插入 DeX 扩展坞时,我的应用程序窗口在 DeX 任务栏中最小化。这是默认行为。

我正在使用运行 DeX 2.5 的 Galaxy S8。

我希望我的应用程序在插入 DeX 后立即显示(全屏或窗口)


到目前为止我所尝试的(根据三星 DeX 网站上的建议)......

1 - 我已经应用了meta-data使应用程序进程保持活动状态的清单:

<meta-data
    android:name="com.samsung.android.keepalive.density"
    android:value="true"/>

2 - 我已应用该configChanges属性来拦截配置更改:

android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"

当设备旋转或在 DeX 界面(即Activity.onConfigurationChanged(Configuration)运行)中调整屏幕大小时,这将按预期工作。

但这不会通过将手机插入 DeX 来触发。

3 - 我的活动已设置为在清单中调整大小:

android:resizeableActivity="true"
android:supportsPictureInPicture="true"

  • 有没有办法让窗口在插入 Dex 时自动显示?
  • 有没有办法在插入 DeX 时获取回调,然后从该回调启动我的应用程序?
4

1 回答 1

2

此信息仅对 DeX v2.5 有效。DeX v3 的更新破坏了以下代码。


当设备与 DeX 对接或脱离时,系统会广播以下意图:

  • android.app.action.ENTER_KNOX_DESKTOP_MODE
  • android.app.action.EXIT_KNOX_DESKTOP_MODE

任何应用程序都可以在清单中注册一个接收器,以便在设备对接时收到通知:

<receiver android:name=".DexReceiver">
    <intent-filter>
        <action android:name="android.app.action.ENTER_KNOX_DESKTOP_MODE"/>
    </intent-filter>
</receiver>

在接收器内部,应用程序可以自行重新启动。

public void onReceive(Context context, Intent intent) {
    Intent relaunch = context.getPackageManager().getLaunchIntentForPackage(BuildConfig.APPLICATION_ID);
    relaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(relaunch);
}

这会导致应用程序在停靠时在正常窗口中启动。


为确保全屏启动,需要在清单中进行 2 处更改。

meta-data1)在块内添加DeX application

<!--DeX FULL SCREEN LAUNCH SIZE-->
<meta-data
    android:name="com.samsung.android.dex.launchwidth"
    android:value="0"/>
<meta-data
    android:name="com.samsung.android.dex.launchheight"
    android:value="0"/>

这里的0值告诉 DeX 使用可能的最大宽度/高度。

2) Add a layout block to the activity that is being launched:

<!--USE BIG ENOUGH DIMENSIONS TO FORCE FULL-SCREEN ON LAUNCH-->
<layout
    android:defaultWidth="5000dp"
    android:defaultHeight="5000dp"
    android:gravity="center"/>

Here the 5000dp values must be bigger than the screen that you are plugging into the DeX.

Both launch size blocks are recommended by Samsung in different places - my experience was that the second option worked on the S8 (DeX v2.5).

于 2019-03-12T11:17:17.947 回答