Skip to content

Firebase messaging-handle background message in kotlin with MainActivity file #1906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
msarkrish opened this issue Jan 30, 2020 · 6 comments
Closed
Labels
type: bug Something isn't working

Comments

@msarkrish
Copy link

I'm using firebase_messaging in my flutter application.
To handle background messages with firebase messaging in pub they suggested to create new Application.java file and replace java file name in AndroidManifest file.

In my application i'm using kotlin and i already implemented some native code in MainActivity.kt

So how to write this code in kotlin.

package io.flutter.plugins.firebasemessagingexample;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
 @Override
public void onCreate() {
 super.onCreate();
 FlutterFirebaseMessagingService.setPluginRegistrant(this);
 }

@Override
public void registerWith(PluginRegistry registry) {
 GeneratedPluginRegistrant.registerWith(registry);
}
}

it is mandatory to replace MainActivity to Application in AndroidManifest file? because i'm having some native code in MainActivity file

@msarkrish msarkrish added the type: bug Something isn't working label Jan 30, 2020
@msarkrish msarkrish changed the title [<FIREBASE_PRODUCT>] <TITLE> Firebase messaging-handle background message in kotlin with MainActivity file Jan 30, 2020
@iapicca
Copy link

iapicca commented Feb 3, 2020

Hi @msarkrish
this doesn't appear to be a bug w/ firebase messaging;
if you need assistance for your code
please see https://flutter.dev/community for resources,
check our guides or
you may also get some help if you post it on Stack Overflow.

Closing, as this isn't an issue with FlutterFire itself,
if you disagree please write in the comments and I will reopen it
Thank you

@iapicca iapicca closed this as completed Feb 3, 2020
@kwent
Copy link

kwent commented Feb 14, 2020

@msarkrish

package io.flutter.plugins.firebasemessagingexample

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

class Application : FlutterApplication(), PluginRegistrantCallback {
  override fun onCreate() {
    super.onCreate()
    FlutterFirebaseMessagingService.setPluginRegistrant(this)
  }

  override fun registerWith(registry: PluginRegistry?) {
    GeneratedPluginRegistrant.registerWith(registry)
  }
}

@iapicca
Copy link

iapicca commented Feb 20, 2020

Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so it's always better to open new issues and reference related issues.

@pneves001
Copy link

This isn't a bug but it is a documentation request for implementing this using Kotlin instead of java since Android is moving away from java development. I'm having the same issue.

@savy-91
Copy link

savy-91 commented Mar 11, 2020

I agree, the documentation could be better and I can't seem to find anything in the community or SO.

@nmshaikh
Copy link

Hi all, I had the same issue in my flutter project. However, when I created an Application.kt file and pasted the code from the README, the Kotlin plugin in IntelliJ automatically prompted to covert the Java code to Kotlin for me:

image

The result was as follows. I simply had to add the override keywords

image

Hope this helps!

@firebase firebase locked and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants