Packages
mob_new
0.3.5
0.4.20
0.4.19
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.45
0.1.44
0.1.43
0.1.42
0.1.40
0.1.33
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.25
0.1.24
0.1.23
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Project generator for the Mob mobile framework
Current section
Files
Jump to
Current section
Files
priv/templates/mob.new/android/app/src/main/java/MobFirebaseService.kt.eex
package <%= bundle_id %>
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import org.json.JSONObject
// Receives FCM messages and token refreshes.
// Token refreshes are cached and delivered to Elixir the next time a screen
// calls Mob.Notify.register_push/0.
// Foreground data pushes are forwarded immediately to the registered screen.
class MobFirebaseService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
pendingToken = token
}
// Called when a data message arrives while the app is in the foreground,
// or when any data-only message arrives regardless of app state.
// If the FCM payload includes mob_notification_json, that JSON is forwarded
// directly; otherwise a JSON object is built from the notification fields.
override fun onMessageReceived(message: RemoteMessage) {
val pid = MobBridge.notifyPid
if (pid == 0L) return
val json = message.data["mob_notification_json"] ?: run {
val notif = message.notification ?: return
JSONObject().apply {
put("title", notif.title ?: "")
put("body", notif.body ?: "")
put("source", "push")
put("data", JSONObject())
}.toString()
}
MobBridge.nativeDeliverNotification(pid, json)
}
companion object {
@Volatile var pendingToken: String? = null
}
}