fix android 12 PendingIntent
This commit is contained in:
parent
d66939244e
commit
158b128510
@ -513,6 +513,7 @@ class MainService : Service() {
|
|||||||
notificationBuilder = NotificationCompat.Builder(this, notificationChannel)
|
notificationBuilder = NotificationCompat.Builder(this, notificationChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedImmutableFlag")
|
||||||
private fun createForegroundNotification() {
|
private fun createForegroundNotification() {
|
||||||
val intent = Intent(this, MainActivity::class.java).apply {
|
val intent = Intent(this, MainActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
@ -520,10 +521,11 @@ class MainService : Service() {
|
|||||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
putExtra("type", type)
|
putExtra("type", type)
|
||||||
}
|
}
|
||||||
val pendingIntent = PendingIntent.getActivity(
|
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
this, 0, intent,
|
PendingIntent.getActivity(this, 0, intent, FLAG_IMMUTABLE)
|
||||||
FLAG_UPDATE_CURRENT
|
} else {
|
||||||
)
|
PendingIntent.getActivity(this, 0, intent, FLAG_UPDATE_CURRENT)
|
||||||
|
}
|
||||||
val notification = notificationBuilder
|
val notification = notificationBuilder
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
@ -581,6 +583,7 @@ class MainService : Service() {
|
|||||||
notificationManager.cancel(getClientNotifyID(clientID))
|
notificationManager.cancel(getClientNotifyID(clientID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedImmutableFlag")
|
||||||
private fun genLoginRequestPendingIntent(res: Boolean): PendingIntent {
|
private fun genLoginRequestPendingIntent(res: Boolean): PendingIntent {
|
||||||
val intent = Intent(this, MainService::class.java).apply {
|
val intent = Intent(this, MainService::class.java).apply {
|
||||||
action = ACTION_LOGIN_REQ_NOTIFY
|
action = ACTION_LOGIN_REQ_NOTIFY
|
||||||
@ -589,7 +592,7 @@ class MainService : Service() {
|
|||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
PendingIntent.getService(this, 111, intent, FLAG_IMMUTABLE)
|
PendingIntent.getService(this, 111, intent, FLAG_IMMUTABLE)
|
||||||
} else {
|
} else {
|
||||||
PendingIntent.getService(this, 111, intent, 0)
|
PendingIntent.getService(this, 111, intent, FLAG_UPDATE_CURRENT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user