Skip to content

Commit

Permalink
Changes in FirebaseFCM class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Idrees committed Jul 18, 2022
1 parent 09fa1ef commit 7248f96
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions firebaseLib/src/main/java/ai/bom/firebase/lib/fcm/FirebaseFCM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ import android.util.Log
import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging

object FirebaseFCM {

fun initializeFCM(context: Context, topic: String) {
try {
FirebaseApp.initializeApp(context)
} catch (e: Exception) {
Log.i(TAG, "onCreate: ${e.message}")
class FirebaseFCM {
companion object {
fun initializeFCM(context: Context, topic: String) {
try {
FirebaseApp.initializeApp(context)
} catch (e: Exception) {
Log.i(TAG, "onCreate: ${e.message}")
}
createNotificationChannel(context)
//Subscribe To Topic
FirebaseMessaging.getInstance().subscribeToTopic(topic)
}
createNotificationChannel(context)
//Subscribe To Topic
FirebaseMessaging.getInstance().subscribeToTopic(topic)
}

fun removeFCMTopic(topic: String) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic)
}
fun removeFCMTopic(topic: String) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic)
}

private fun createNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelId = context.getString(R.string.default_notification_channel_id)
val channelName = context.getString(R.string.default_notification_channel_name)
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(
NotificationChannel(
channelId,
channelName, NotificationManager.IMPORTANCE_DEFAULT
private fun createNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelId = context.getString(R.string.default_notification_channel_id)
val channelName = context.getString(R.string.default_notification_channel_name)
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(
NotificationChannel(
channelId,
channelName, NotificationManager.IMPORTANCE_DEFAULT
)
)
)
}
}
}
}

0 comments on commit 7248f96

Please sign in to comment.