Skip to content

Commit

Permalink
[fix] 修复高版本(S以上)媒体检查更新通知错误导致失败
Browse files Browse the repository at this point in the history
  • Loading branch information
RyensX committed Oct 12, 2024
1 parent 9aa45a0 commit e983dfd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/su/mediabox/work/MediaUpdateCheckWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ internal class MediaUpdateCheckWorker(context: Context, workerParameters: Worker
private val TAG = "媒体检查更新Worker"
private val key = ResourceUtil.getString(R.string.media_update_check_title)

private val notifyFlag =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_UPDATE_CURRENT

private fun createForegroundInfo(): ForegroundInfo {
// val cancel = applicationContext.getString(R.string.cancel)
// val intent = WorkManager.getInstance(applicationContext)
Expand All @@ -77,7 +81,7 @@ internal class MediaUpdateCheckWorker(context: Context, workerParameters: Worker
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val notifyPendingIntent = PendingIntent.getActivity(
applicationContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT
applicationContext, 0, notifyIntent, notifyFlag
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand Down Expand Up @@ -179,7 +183,7 @@ internal class MediaUpdateCheckWorker(context: Context, workerParameters: Worker

val pluginMediaDataManageNotifyPendingIntent = PendingIntent.getActivity(
applicationContext, index,
pluginMediaDataManageIntent, PendingIntent.FLAG_UPDATE_CURRENT
pluginMediaDataManageIntent, notifyFlag
)

val pluginMediaUpdateNofBuilder =
Expand Down Expand Up @@ -216,7 +220,7 @@ internal class MediaUpdateCheckWorker(context: Context, workerParameters: Worker
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val notifyPendingIntent = PendingIntent.getActivity(
applicationContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT
applicationContext, 0, notifyIntent, notifyFlag
)

val mediaUpdateCheckNofBuilder =
Expand Down

0 comments on commit e983dfd

Please sign in to comment.