Browse Source
Merge pull request #12964 from t895/foreground-service-test
Merge pull request #12964 from t895/foreground-service-test
android: Remove foreground servicence_cpp
committed by
GitHub
26 changed files with 0 additions and 176 deletions
-
6src/android/app/src/main/AndroidManifest.xml
-
12src/android/app/src/main/java/org/yuzu/yuzu_emu/YuzuApplication.kt
-
17src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
-
9src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
-
70src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt
-
3src/android/app/src/main/res/values-ar/strings.xml
-
3src/android/app/src/main/res/values-ckb/strings.xml
-
1src/android/app/src/main/res/values-cs/strings.xml
-
3src/android/app/src/main/res/values-de/strings.xml
-
3src/android/app/src/main/res/values-es/strings.xml
-
3src/android/app/src/main/res/values-fr/strings.xml
-
3src/android/app/src/main/res/values-he/strings.xml
-
3src/android/app/src/main/res/values-hu/strings.xml
-
3src/android/app/src/main/res/values-it/strings.xml
-
3src/android/app/src/main/res/values-ja/strings.xml
-
3src/android/app/src/main/res/values-ko/strings.xml
-
3src/android/app/src/main/res/values-nb/strings.xml
-
3src/android/app/src/main/res/values-pl/strings.xml
-
3src/android/app/src/main/res/values-pt-rBR/strings.xml
-
3src/android/app/src/main/res/values-pt-rPT/strings.xml
-
3src/android/app/src/main/res/values-ru/strings.xml
-
3src/android/app/src/main/res/values-uk/strings.xml
-
3src/android/app/src/main/res/values-vi/strings.xml
-
3src/android/app/src/main/res/values-zh-rCN/strings.xml
-
3src/android/app/src/main/res/values-zh-rTW/strings.xml
-
4src/android/app/src/main/res/values/strings.xml
@ -1,70 +0,0 @@ |
|||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project |
|||
// SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
package org.yuzu.yuzu_emu.utils |
|||
|
|||
import android.app.PendingIntent |
|||
import android.app.Service |
|||
import android.content.Intent |
|||
import android.os.IBinder |
|||
import androidx.core.app.NotificationCompat |
|||
import androidx.core.app.NotificationManagerCompat |
|||
import org.yuzu.yuzu_emu.R |
|||
import org.yuzu.yuzu_emu.activities.EmulationActivity |
|||
|
|||
/** |
|||
* A service that shows a permanent notification in the background to avoid the app getting |
|||
* cleared from memory by the system. |
|||
*/ |
|||
class ForegroundService : Service() { |
|||
companion object { |
|||
const val EMULATION_RUNNING_NOTIFICATION = 0x1000 |
|||
|
|||
const val ACTION_STOP = "stop" |
|||
} |
|||
|
|||
private fun showRunningNotification() { |
|||
// Intent is used to resume emulation if the notification is clicked |
|||
val contentIntent = PendingIntent.getActivity( |
|||
this, |
|||
0, |
|||
Intent(this, EmulationActivity::class.java), |
|||
PendingIntent.FLAG_IMMUTABLE |
|||
) |
|||
val builder = |
|||
NotificationCompat.Builder(this, getString(R.string.emulation_notification_channel_id)) |
|||
.setSmallIcon(R.drawable.ic_stat_notification_logo) |
|||
.setContentTitle(getString(R.string.app_name)) |
|||
.setContentText(getString(R.string.emulation_notification_running)) |
|||
.setPriority(NotificationCompat.PRIORITY_LOW) |
|||
.setOngoing(true) |
|||
.setVibrate(null) |
|||
.setSound(null) |
|||
.setContentIntent(contentIntent) |
|||
startForeground(EMULATION_RUNNING_NOTIFICATION, builder.build()) |
|||
} |
|||
|
|||
override fun onBind(intent: Intent): IBinder? { |
|||
return null |
|||
} |
|||
|
|||
override fun onCreate() { |
|||
showRunningNotification() |
|||
} |
|||
|
|||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { |
|||
if (intent == null) { |
|||
return START_NOT_STICKY |
|||
} |
|||
if (intent.action == ACTION_STOP) { |
|||
NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION) |
|||
stopForeground(STOP_FOREGROUND_REMOVE) |
|||
stopSelfResult(startId) |
|||
} |
|||
return START_STICKY |
|||
} |
|||
|
|||
override fun onDestroy() { |
|||
NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION) |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue