rns-nativecall 0.4.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,5 +72,49 @@ class CallMessagingService : FirebaseMessagingService() {
72
72
  }
73
73
  }
74
74
 
75
- // ... showMissedCallNotification and isAppInForeground remain the same as your snippet
75
+ private fun showMissedCallNotification(context: Context, data: Map<String, String>, uuid: String) {
76
+ val name = data["name"] ?: "Unknown"
77
+ val callType = data["callType"] ?: "video"
78
+ val channelId = "missed_calls"
79
+ val article = if (callType.startsWith("a", ignoreCase = true)) "an" else "a"
80
+ val appName = context.applicationInfo.loadLabel(context.packageManager).toString()
81
+ val capitalizedAppName = appName.replaceFirstChar { it.uppercase() }
82
+
83
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
84
+
85
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
86
+ val channel = NotificationChannel(channelId, "Missed Calls", NotificationManager.IMPORTANCE_HIGH)
87
+ notificationManager.createNotificationChannel(channel)
88
+ }
89
+
90
+ val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
91
+ val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
92
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
93
+ } else {
94
+ PendingIntent.FLAG_UPDATE_CURRENT
95
+ }
96
+ val contentIntent = PendingIntent.getActivity(context, uuid.hashCode(), launchIntent, pendingFlags)
97
+
98
+ var iconResId = context.resources.getIdentifier("ic_missed_call", "drawable", context.packageName)
99
+ if (iconResId == 0) iconResId = android.R.drawable.sym_call_missed
100
+
101
+ val builder = NotificationCompat.Builder(context, channelId)
102
+ .setSmallIcon(iconResId)
103
+ .setContentTitle("$capitalizedAppName missed call")
104
+ .setContentText("You missed $article $callType call from $name")
105
+ .setPriority(NotificationCompat.PRIORITY_HIGH)
106
+ .setAutoCancel(true)
107
+ .setContentIntent(contentIntent)
108
+ .setCategory(NotificationCompat.CATEGORY_MISSED_CALL)
109
+
110
+ notificationManager.notify(uuid.hashCode(), builder.build())
111
+ }
112
+
113
+ private fun isAppInForeground(context: Context): Boolean {
114
+ val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
115
+ val appProcesses = activityManager.runningAppProcesses ?: return false
116
+ return appProcesses.any {
117
+ it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && it.processName == context.packageName
118
+ }
119
+ }
76
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.4.9",
3
+ "version": "0.5.0",
4
4
  "description": "RNS nativecall component with native Android/iOS for handling native call ui, when app is not open or open.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",