1

I am getting this error when receiving push notification only when the app is open, foreground mode!

Does anyone had this issue before using the Firebase push notification and react-native-fcm?

COde:

      showLocalNotification(notif) {
        FCM.presentLocalNotification({
            title: notif.title,
            body: notif.body,
            priority: "high",
            click_action: notif.click_action,
            show_in_foreground: true,
            local: true
        });
    }

Mainapplication.java:


public class MainApplication extends MultiDexApplication {

  // Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add cool native modules
//            new MainReactPackage(),

            new RNBackgroundGeolocation(),
            // Needed for `react-native link`

            new FIRMessagingPackage(),
            //new RNBackgroundGeolocation(),
            //new RNFirebasePackage(),
            new VectorIconsPackage()
            //new RNFirebaseMessagingPackage()
    );
  }
}

Full Error I am getting:

java.lang.ClassCastException: fi.rogerstudio.possis.MainApplication cannot be cast to com.facebook.react.ReactApplication at com.evollu.react.fcm.MessagingService$1.run(MessagingService.java:41) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Mizlul
  • 1
  • 7
  • 41
  • 100

1 Answers1

0

For someone who may be coming to this 3.5 years after the fact, the solution is to make sure your main application extends ReactApplication,

public class MainApplication extends MultiDexApplication, ReactApplication

and then implement getReactNativeHost like this:

public class MainApplication extends MultiDexApplication {
  ...
  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }
 ...
}