Skip to content

Instantly share code, notes, and snippets.

@Kudo
Created June 26, 2022 06:53
Show Gist options
  • Save Kudo/b8d6a7e75d951fa6652fe255c2068bd0 to your computer and use it in GitHub Desktop.
Save Kudo/b8d6a7e75d951fa6652fe255c2068bd0 to your computer and use it in GitHub Desktop.
expo-notifications #17966 fix
diff --git a/node_modules/expo-notifications/android/src/main/AndroidManifest.xml b/node_modules/expo-notifications/android/src/main/AndroidManifest.xml
index 2b2fa5e..411f832 100644
--- a/node_modules/expo-notifications/android/src/main/AndroidManifest.xml
+++ b/node_modules/expo-notifications/android/src/main/AndroidManifest.xml
@@ -34,6 +34,7 @@
android:excludeFromRecents="true"
android:noHistory="true"
android:launchMode="standard"
+ android:taskAffinity=""
/>
</application>
</manifest>
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationForwarderActivity.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationForwarderActivity.kt
index 0dbd2ea..b700ae4 100644
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationForwarderActivity.kt
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationForwarderActivity.kt
@@ -3,7 +3,9 @@ package expo.modules.notifications.service
import android.app.Activity
import android.content.Intent
import android.os.Bundle
+import android.util.Log
import expo.modules.notifications.BuildConfig
+import expo.modules.notifications.service.delegates.ExpoHandlingDelegate
/**
* An internal Activity that passes given Intent extras from
@@ -15,6 +17,14 @@ class NotificationForwarderActivity : Activity() {
super.onCreate(savedInstanceState)
val broadcastIntent =
NotificationsService.createNotificationResponseBroadcastIntent(applicationContext, intent.extras)
+
+ val foregroundLaunchActivityIntent = ExpoHandlingDelegate.getForegroundLaunchActivityIntent(this)
+ if (foregroundLaunchActivityIntent != null) {
+ val notificationResponse = NotificationsService.getNotificationResponseFromBroadcastIntent(broadcastIntent)
+ NotificationsService.setNotificationResponseToIntent(foregroundLaunchActivityIntent, notificationResponse)
+ startActivity(foregroundLaunchActivityIntent)
+ }
+
sendBroadcast(broadcastIntent)
finish()
}
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt
index 98b1da9..1021c71 100644
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt
@@ -67,15 +67,22 @@ class ExpoHandlingDelegate(protected val context: Context) : HandlingDelegate {
// For intent with RemoteInput, it should be mutable.
intentFlags = intentFlags or PendingIntent.FLAG_MUTABLE
}
- val foregroundActivityIntent = getNotificationActionLauncher(context) ?: getMainActivityLauncher(context) ?: run {
- Log.w("expo-notifications", "No launch intent found for application. Interacting with the notification won't open the app. The implementation uses `getLaunchIntentForPackage` to find appropriate activity.")
- Intent()
- }
- foregroundActivityIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
- NotificationsService.setNotificationResponseToIntent(foregroundActivityIntent, notificationResponse)
+
val backgroundActivityIntent = Intent(context, NotificationForwarderActivity::class.java)
+ backgroundActivityIntent.data = broadcastIntent.data
+ backgroundActivityIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
backgroundActivityIntent.putExtras(broadcastIntent)
- return PendingIntent.getActivities(context, 0, arrayOf(foregroundActivityIntent, backgroundActivityIntent), intentFlags)
+ val requestCode = broadcastIntent.component?.className?.hashCode() ?: NotificationsService::class.java.hashCode()
+ return PendingIntent.getActivity(context, requestCode, backgroundActivityIntent, intentFlags)
+ }
+
+ fun getForegroundLaunchActivityIntent(context: Context): Intent? {
+ val intent = getNotificationActionLauncher(context)
+ ?: ExpoHandlingDelegate.getMainActivityLauncher(context) ?: run {
+ Log.w("expo-notifications", "No launch intent found for application. Interacting with the notification won't open the app. The implementation uses `getLaunchIntentForPackage` to find appropriate activity.")
+ return null
+ }
+ return intent
}
private fun getNotificationActionLauncher(context: Context): Intent? {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment