works on lg g6

This commit is contained in:
Martin Ptáček
2023-07-25 12:04:08 +02:00
parent d7ab24175c
commit 7f24e2a6db
2 changed files with 21 additions and 15 deletions

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<targetSelectedWithDropDown> <runningDeviceTargetSelectedWithDropDown>
<Target> <Target>
<type value="QUICK_BOOT_TARGET" /> <type value="RUNNING_DEVICE_TARGET" />
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <type value="SERIAL_NUMBER" />
<value value="$USER_HOME$/.android/avd/Pixel_XL_API_31.avd" /> <value value="LGH8702b43aa49" />
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-07-11T15:42:03.701126601Z" /> <timeTargetWasSelectedWithDropDown value="2023-07-25T09:59:23.293322749Z" />
</component> </component>
</project> </project>

View File

@ -4,7 +4,9 @@ package com.birdthedeveloper.prometheus.android.exporter.worker
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo import androidx.work.ForegroundInfo
@ -127,19 +129,18 @@ class PromWorker(
val inputConfiguration: PromConfiguration = PromConfiguration.fromWorkData(inputData) val inputConfiguration: PromConfiguration = PromConfiguration.fromWorkData(inputData)
Log.d(TAG, "Launching PromWorker with the following config: $inputConfiguration") Log.d(TAG, "Launching PromWorker with the following config: $inputConfiguration")
// set foreground - //TODO is this right for the use case?
//setForeground(createForegroundInfo())
startServicesInOneThread(inputConfiguration) startServicesInOneThread(inputConfiguration)
return Result.success() return Result.success()
} }
override suspend fun getForegroundInfo(): ForegroundInfo {
return createForegroundInfo()
}
//TODO foreground notification
private fun createForegroundInfo(): ForegroundInfo { private fun createForegroundInfo(): ForegroundInfo {
val id = "channel_id" val id = "id1"
val title = "title" val title = "title1"
val cancel = "cancel_download" val cancel = "cancel1"
// This PendingIntent can be used to cancel the worker // This PendingIntent can be used to cancel the worker
val intent = WorkManager.getInstance(applicationContext) val intent = WorkManager.getInstance(applicationContext)
.createCancelPendingIntent(getId()) .createCancelPendingIntent(getId())
@ -147,7 +148,7 @@ class PromWorker(
val notification = NotificationCompat.Builder(applicationContext, id) val notification = NotificationCompat.Builder(applicationContext, id)
.setContentTitle(title) .setContentTitle(title)
.setTicker(title) .setTicker(title)
.setContentText("progress") .setContentText("progress1")
.setSmallIcon(R.drawable.ic_launcher_foreground) .setSmallIcon(R.drawable.ic_launcher_foreground)
.setOngoing(true) .setOngoing(true)
// Add the cancel action to the notification which can // Add the cancel action to the notification which can
@ -155,7 +156,12 @@ class PromWorker(
.addAction(android.R.drawable.ic_delete, cancel, intent) .addAction(android.R.drawable.ic_delete, cancel, intent)
.build() .build()
return ForegroundInfo(1, notification) return ForegroundInfo(0, notification)
}
companion object {
const val KEY_INPUT_URL = "KEY_INPUT_URL"
const val KEY_OUTPUT_FILE_NAME = "KEY_OUTPUT_FILE_NAME"
} }
} }