Ich verwende Workmanager in meiner Android -Anwendung, um Hintergrundarbeiten zu erledigen. /> Ich kann es nicht zuverlässig auf meinem Pixel 7 -API 35 -Emulator zum Laufen bringen - Warum könnte das sein? AndroidManifest.xml :
class LocationWorker(
context: Context,
workerParams: WorkerParameters
): CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result {
// ... (1. Getting the location and storing it in a local database)
if (isNetworkAvailable(applicationContext)) {
// Always get here when the app is visible on-screen
Log.d("LocationWorker", "Uploading location.")
// ... (2. Uploading the data from the database to a remote API)
} else {
// Always get here when not having the app on-screen
Log.d("LocationWorker", "Network not available.")
}
}
private fun isNetworkAvailable(context: Context): Boolean {
val connectivityManager = context.getSystemService(ConnectivityManager::class.java)
val network = connectivityManager.activeNetwork ?: return false
val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
}
< /code>
I ensured that the device itself has WiFi enabled, the app is not stripped of permissions when unused and all permissions are allowed.
Minimum SDK version is 29 (Android 10).
Minimal demo to reproduce the problem
I've created a minimal example of the [url=viewtopic.php?t=15738]problem[/url] on GitHub.
The second commit shows all that there is to the application (plus a README.md
Ich verwende Workmanager in meiner Android -Anwendung, um Hintergrundarbeiten zu erledigen. /> Ich kann es nicht zuverlässig auf meinem Pixel 7 -API 35 -Emulator zum Laufen bringen - Warum könnte das sein? AndroidManifest.xml : [code]
< /code> MainActivity.kt[/code]-20S Delay ermöglicht es mir, vor der Arbeit woanders im Vordergrund zu gehen: [code]val oneTimeRequest = OneTimeWorkRequestBuilder() .setInitialDelay(20, TimeUnit.SECONDS) .build() WorkManager.getInstance(context) .enqueue(oneTimeRequest) < /code> Worker.kt[/code]: [code]class LocationWorker( context: Context, workerParams: WorkerParameters ): CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result {
// ... (1. Getting the location and storing it in a local database)
if (isNetworkAvailable(applicationContext)) { // Always get here when the app is visible on-screen Log.d("LocationWorker", "Uploading location.") // ... (2. Uploading the data from the database to a remote API) } else { // Always get here when not having the app on-screen Log.d("LocationWorker", "Network not available.") } }
private fun isNetworkAvailable(context: Context): Boolean { val connectivityManager = context.getSystemService(ConnectivityManager::class.java) val network = connectivityManager.activeNetwork ?: return false val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) } < /code> I ensured that the device itself has WiFi enabled, the app is not stripped of permissions when unused and all permissions are allowed. Minimum SDK version is 29 (Android 10). Minimal demo to reproduce the problem I've created a minimal example of the [url=viewtopic.php?t=15738]problem[/url] on GitHub. The second commit shows all that there is to the application (plus a README.md[/code]). Jetzt ...
WorkManager ist eine Bibliothek, die zum Einreihen von Arbeiten in die Warteschlange verwendet wird, deren Ausführung garantiert ist, nachdem ihre Einschränkungen erfüllt sind.
Ich versuche, mit meinem Computer eine Verbindung zu einem Gerät herzustellen, indem ich den visa.ivi-Treiber verwende. Ich schreibe in C# mit Visual Studio 17.12.3.
Ich habe ein Programm mit...
Problem:
Ich versuche, Hintergrundaufgaben in meiner Flutter -App zu implementieren, um Benutzer Online -Datenbank hinzuzufügen, wenn das Gerät online mit Workmanager ist. Nachdem ich den Workmanager...
Problem:
Ich versuche, Hintergrundaufgaben in meiner Flutter -App zu implementieren, um Benutzer Online -Datenbank hinzuzufügen, wenn das Gerät online mit Workmanager ist. Nachdem ich den Workmanager...
Ich musste WorkManager in einer mobilen App verwenden, damit es aktuelle Benutzernotfälle mithilfe eines PeriodicWorkRequest erfassen kann.
Aber aufgrund meiner fehlenden Dokumentation habe ich es...