启用ACTIVE_TILE时,启动时快速设置磁贴处于活动状态

br.*_*br. 5 android

当您使用META_DATA_ACTIVE_TILE时,onStartListening()TileService回调(当您调用TileService.requestListeningState()时,将更新Tile状态)将触发。

它可以工作,但是当设备启动时,Tile处于活动状态,直到您单击它为止。如果未设置ACTIVE_TILE,则磁贴在引导时保持不活动状态。

怎么解决呢?

Android 7.1.2

jua*_*o87 7

我认为在这种情况下文档不是很清楚。我遇到了同样的问题,经过多次尝试,我找到了适合我的案例的解决方案。

清单保持:

<meta-data android:name="android.service.quicksettings.ACTIVE_TILE"
            android:value="true" />
Run Code Online (Sandbox Code Playgroud)

然后在 quickTileService 覆盖 onBind 并调用 RequestListeningState:

override fun onBind(intent: Intent?): IBinder {
    TileService.requestListeningState(this,
            ComponentName(this, QSTileService::class.java))
    return super.onBind(intent)
}
Run Code Online (Sandbox Code Playgroud)

在 onStartListening 上,您可以更新您的磁贴:

override fun onStartListening() {
    super.onStartListening()
    updateTile()
}
Run Code Online (Sandbox Code Playgroud)