Skip to content

Commit

Permalink
Update flag check for API 31
Browse files Browse the repository at this point in the history
  • Loading branch information
pmtkh committed Aug 16, 2022
1 parent cefe7c0 commit fe398f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/android/com/adobe/phonegap/push/FCMService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,16 @@ class FCMService : FirebaseMessagingService() {
notificationIntent.putExtra(PushConstants.NOT_ID, notId)
val random = SecureRandom()
var requestCode = random.nextInt()
val updateActivityFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
val contentIntent = PendingIntent.getActivity(
this,
requestCode,
notificationIntent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
updateActivityFlag
)
val dismissedNotificationIntent = Intent(
this,
Expand All @@ -467,11 +472,16 @@ class FCMService : FirebaseMessagingService() {

requestCode = random.nextInt()

val deleteActivityFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_CANCEL_CURRENT
}
val deleteIntent = PendingIntent.getBroadcast(
this,
requestCode,
dismissedNotificationIntent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
deleteActivityFlag
)

val mBuilder: NotificationCompat.Builder =
Expand Down Expand Up @@ -668,7 +678,11 @@ class FCMService : FirebaseMessagingService() {
var intent: Intent?
var pIntent: PendingIntent?
val callback = action.getString(PushConstants.CALLBACK)

val updateActivityFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
when {
inline -> {
Log.d(TAG, "Version: ${Build.VERSION.SDK_INT} = ${Build.VERSION_CODES.M}")
Expand All @@ -683,14 +697,21 @@ class FCMService : FirebaseMessagingService() {

updateIntent(intent, callback, extras, foreground, notId)

val oneShotActivityFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_ONE_SHOT
}

pIntent = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
Log.d(TAG, "push activity for notId $notId")


PendingIntent.getActivity(
this,
uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ONE_SHOT
oneShotActivityFlag
)
} else {
Log.d(TAG, "push receiver for notId $notId")
Expand All @@ -699,7 +720,7 @@ class FCMService : FirebaseMessagingService() {
this,
uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ONE_SHOT
oneShotActivityFlag
)
}
}
Expand All @@ -710,7 +731,7 @@ class FCMService : FirebaseMessagingService() {
pIntent = PendingIntent.getActivity(
this, uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
updateActivityFlag
)
}

Expand All @@ -720,7 +741,7 @@ class FCMService : FirebaseMessagingService() {
pIntent = PendingIntent.getBroadcast(
this, uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
updateActivityFlag
)
}
}
Expand Down Expand Up @@ -764,8 +785,10 @@ class FCMService : FirebaseMessagingService() {
mBuilder.extend(NotificationCompat.WearableExtender().addActions(wActions))
wActions.clear()
} catch (e: JSONException) {
// nope
Log.d(TAG, "Create actions error: ${e.message}")
}
} else {
Log.d(TAG, "No action to perform")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/FullScreenActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FullScreenActivity : Activity() {

protected override fun onDestroy() {
super.onDestroy()
Log.d(LOG_TAG, "onDestroy")
turnScreenOffAndKeyguardOn()
}

Expand Down

0 comments on commit fe398f6

Please sign in to comment.