小编A.S*_*.SD的帖子

如何正确触发ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS意图?

如文档中所述:

"An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog."

Can someone tell me the proper way to fire this intent?

optimization android android-intent android-6.0-marshmallow android-doze

31
推荐指数
2
解决办法
2万
查看次数

Kotlin是否与Java的Collections.synchronizedList等效?还是在Kotlin中不需要

在Kotlin中进行编码,需要如下所述的线程安全列表:java并发数组列表访问

似乎Collections.kt没有此功能。Kotlin的可变列表已经是线程安全的吗?如果没有,我该怎么做?

谢谢。

java concurrency list thread-safety kotlin

12
推荐指数
1
解决办法
5555
查看次数

在 Kotlin 中,将 Long 转换为 uint32 ByteArray 并将 Int 转换为 uint8 的最简洁方法是什么?

fun longToByteArray(value: Long): ByteArray {
    val bytes = ByteArray(8)
    ByteBuffer.wrap(bytes).putLong(value)
    return Arrays.copyOfRange(bytes, 4, 8)
}

fun intToUInt8(value: Int): ByteArray {
    val bytes = ByteArray(4)
    ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).putInt(value and 0xff)
    var array = Arrays.copyOfRange(bytes, 0, 1)
    return array
}
Run Code Online (Sandbox Code Playgroud)

我认为这些是一些 Java 方法的 Kotlin 等价物,但我想知道这些方法在 Kotlin 中是否正确/必要。

编辑:根据评论修复示例,还演示了不断变化的字节顺序。感谢您的反馈。我将接受演示如何在没有 ByteBuffer 的情况下执行此操作的答案。

arrays android byte uint32 kotlin

4
推荐指数
1
解决办法
4285
查看次数

如何使用工作管理器 2.0 返回 ListenableFuture<Result>?

似乎 ListenableWorker 不再具有 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 限制,但是我无法弄清楚或找到有关如何在我覆盖的 startWork() 函数中正确返回 ListenableFuture< Result> 的示例。

据我所知,唯一的选择是返回一个 SettableFuture.create<Result>() 但这仍然需要抑制“RestrictedApi”警告/错误。

有人知道更简单的方法吗?

编辑:据我所知,这是使用 CallbackToFutureAdapter.Completer 的方法

override fun startWork(): ListenableFuture<Result> {
    return CallbackToFutureAdapter.getFuture({
        it.set(ListenableWorker.Result.success())
    })

}
Run Code Online (Sandbox Code Playgroud)

android android-workmanager androidx

4
推荐指数
1
解决办法
2097
查看次数