Skip to content

Commit baa9122

Browse files
authored
fix: Improve background running notification (#2614)
1 parent b70fc03 commit baa9122

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

app/src/main/java/app/revanced/manager/patcher/worker/PatcherWorker.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import android.os.Parcelable
1414
import android.os.PowerManager
1515
import android.util.Log
1616
import androidx.activity.result.ActivityResult
17-
import androidx.core.content.ContextCompat
1817
import androidx.work.ForegroundInfo
1918
import androidx.work.WorkerParameters
19+
import app.revanced.manager.MainActivity
2020
import app.revanced.manager.R
2121
import app.revanced.manager.data.platform.Filesystem
2222
import app.revanced.manager.data.room.apps.installed.InstallType
@@ -88,22 +88,25 @@ class PatcherWorker(
8888
)
8989

9090
private fun createNotification(): Notification {
91-
val notificationIntent = Intent(applicationContext, PatcherWorker::class.java)
92-
val pendingIntent: PendingIntent = PendingIntent.getActivity(
91+
val notificationIntent = Intent(applicationContext, MainActivity::class.java).apply {
92+
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
93+
}
94+
val pendingIntent = PendingIntent.getActivity(
9395
applicationContext, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE
9496
)
9597
val channel = NotificationChannel(
96-
"revanced-patcher-patching", "Patching", NotificationManager.IMPORTANCE_HIGH
98+
"revanced-patcher-patching", "Patching", NotificationManager.IMPORTANCE_LOW
9799
)
98100
val notificationManager =
99-
ContextCompat.getSystemService(applicationContext, NotificationManager::class.java)
100-
notificationManager!!.createNotificationChannel(channel)
101+
applicationContext.getSystemService(NotificationManager::class.java)
102+
notificationManager.createNotificationChannel(channel)
101103
return Notification.Builder(applicationContext, channel.id)
102-
.setContentTitle(applicationContext.getText(R.string.app_name))
103-
.setContentText(applicationContext.getText(R.string.patcher_notification_message))
104-
.setLargeIcon(Icon.createWithResource(applicationContext, R.drawable.ic_notification))
104+
.setContentTitle(applicationContext.getText(R.string.patcher_notification_title))
105+
.setContentText(applicationContext.getText(R.string.patcher_notification_text))
105106
.setSmallIcon(Icon.createWithResource(applicationContext, R.drawable.ic_notification))
106-
.setContentIntent(pendingIntent).build()
107+
.setContentIntent(pendingIntent)
108+
.setCategory(Notification.CATEGORY_SERVICE)
109+
.build()
107110
}
108111

109112
override suspend fun doWork(): Result {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@
317317
<string name="patcher_step_group_saving">Saving</string>
318318
<string name="patcher_step_write_patched">Write patched APK file</string>
319319
<string name="patcher_step_sign_apk">Sign patched APK file</string>
320-
<string name="patcher_notification_message">Patching in progress…</string>
320+
<string name="patcher_notification_title">Patching in progress…</string>
321+
<string name="patcher_notification_text">Tap to return to the patcher</string>
321322
<string name="patcher_stop_confirm_title">Stop patcher</string>
322323
<string name="patcher_stop_confirm_description">Are you sure you want to stop the patching process?</string>
323324
<string name="execute_patches">Execute patches</string>

0 commit comments

Comments
 (0)