如文档中所述:
"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
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 的情况下执行此操作的答案。
似乎 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 ×3
kotlin ×2
android-doze ×1
androidx ×1
arrays ×1
byte ×1
concurrency ×1
java ×1
list ×1
optimization ×1
uint32 ×1