zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.76k stars 2.05k forks source link

Android crash when reveived notification #796

Closed quocman1982 closed 4 years ago

quocman1982 commented 6 years ago

Everything working until it receive an notification

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.seller, PID: 15468 java.lang.ClassCastException: com.google.android.gms.iid.zzi cannot be cast to com.google.firebase.iid.zzf at com.google.firebase.iid.zzh.onServiceConnected(Unknown Source:4) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1730) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1762) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.seller">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"

  android:theme="@style/AppTheme">

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
      android:launchMode="singleTop"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>

            <!-- <Else> -->
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
            <!-- </Else> -->
        </intent-filter>
    </service>
</application>

Can you help me ?

metinvio commented 4 years ago

I don't know guys, it sound really weird but this solved my problem: I changed "react-native-push-notification": "^3.1.9" to "react-native-push-notification": "3.1.9" by doing: yarn add react-native-push-notification@3.1.9

I don't know where the "^" came from or why it's causing problems but I'm so happy that it's solved. Hopefully it will help some of you.

Dallas62 commented 4 years ago

Hi @metinvio Do not use this solution, the library in this version as too many bugs. Please paste your AndroidManifest, there is probably extra data not needed such as GCM.

metinvio commented 4 years ago

Hi @Dallas62

this is my manifest, but when I remove GcmReceiver, other devices wont receive push notifications. And when I leave it my device crashes when receiving push.

  <meta-data  
    android:name="com.dieam.reactnativepushnotification.notification_color"
    android:resource="@android:color/white"/>

    <!-- < Only if you're using GCM or localNotificationScheduhale() > -->
    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

    <!-- < Only if you're using GCM or localNotificationSchedule() > -->
    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <!-- </ Only if you're using GCM or localNotificationSchedule() > -->
Dallas62 commented 4 years ago

Yes this is normal, you have to change your AndroidManifest to this: https://github.com/zo0r/react-native-push-notification#android-manual-installation

 <meta-data  
    android:name="com.dieam.reactnativepushnotification.notification_color"
    android:resource="@android:color/white"/>

        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

       <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
metinvio commented 4 years ago

@Dallas62 Yes now it doesn't crash anymore and I receive push-notifications in debug and release. But my customer doesn't receive any. Do you think it is caused by Android API Level or his device configs?

Dallas62 commented 4 years ago

I think this is related to the default channel_id of firebase which is not set. Take a look to recent issues about “popup”. Like #1495 and #1479