rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
288 stars 329 forks source link

How do I manually initialize Firebase in the callback? #209

Open dev-naiksan opened 3 years ago

dev-naiksan commented 3 years ago

According to the documentation, if (registry?.hasPlugin("io.flutter.plugins.pathprovider") == false) { PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider")) } This is the way to do it. What about Firebase? I am using CloudFirestore plugin for pushing the location to the CloudFirestore db.

Satendra124 commented 3 years ago

did you found a way?

JeanRoldanDev commented 3 years ago
import io.flutter.plugins.firebase.database.FirebaseDatabasePlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

 override fun onCreate() {
        super.onCreate()
        IsolateHolderService.setPluginRegistrant(this)
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
        createNotificationChannels()
        FlutterMain.startInitialization(this)
    }

   override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("io.flutter.plugins.firebase.database")) {
            FirebaseDatabasePlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebase.database"))
        }
        if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
            FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging"))
        }
    }

    fun createNotificationChannels() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val name = "groupChannel";
            val descriptionText = "This is the group channel";
            val importance = NotificationManager.IMPORTANCE_MAX;
            val mChannel = NotificationChannel("59054", name, importance);
            mChannel.description = descriptionText;
            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager;
            notificationManager.createNotificationChannel(mChannel);
        }
    }