Skip to content
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

onNotification is not called when a remote notification is pressed on Android #1378

Closed
anisimov74 opened this issue Apr 20, 2020 · 94 comments
Closed

Comments

@anisimov74
Copy link

anisimov74 commented Apr 20, 2020

Hi,
onNotification is not get called when i press a notification.
The doc https://github.com/zo0r/react-native-push-notification#usage says that
onNotification Called when a remote or local notification is opened or received.

This callback is called twice when a notification is received:
1.
{collapse_key: "XX" foreground: true google.delivered_priority: "high" google.message_id: "0:1587387492329033%3a743ff23a743ff2" google.original_priority: "high" google.sent_time: 1587387492305 google.ttl: 2419200 id: "-1393396919" issueId: "XX" notification: body: "XX" sound: "default" tag: "XX" title: "XX" userInteraction: false}
2.
{foreground: true id: "-1409941121" issueId: "XX" message: "XX" title: "XX" userId: "XX" userInteraction: false}

Can anybody help me with this problem?

@gibrandev
Copy link

same here

@Dallas62
Copy link
Collaborator

Hi!
Can you provide manifest.xml ?
You probably add the GCM receiver which is not needed.

@anisimov74
Copy link
Author

anisimov74 commented Apr 20, 2020

@Dallas62 here it is

<uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

<uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:usesCleartextTraffic="true"
      android:label="@string/app_name"
      android:icon="@mipmap/logo"
      android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_notification"/>

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

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value=""/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value=""/>

        <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <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="XX" />
            </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() > -->

        <!-- < Else > -->
        <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

@anisimov74
Copy link
Author

anisimov74 commented Apr 20, 2020

I'm also unable to get onNotification called when the app in a background mode or killed.
PushNotification.popInitialNotification always returns null

@anisimov74
Copy link
Author

@Dallas62 I'm using Firebase to send remote notifications.

@Dallas62
Copy link
Collaborator

Dallas62 commented Apr 20, 2020

There is conditional configuration in the documentation, look in the comments there is if else, remove those with GCM in the manifest

@anisimov74
Copy link
Author

anisimov74 commented Apr 20, 2020

@Dallas62 thank you for reviewing. I changed the content to the following, but it didn't help

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:usesCleartextTraffic="true"
      android:label="@string/app_name"
      android:icon="@mipmap/logo"
      android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_notification"/>

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

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value=""/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value=""/>

        <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>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

@Dallas62
Copy link
Collaborator

Dallas62 commented Apr 20, 2020

Does something changed or nothing changed ?
What is the new comportement ?
Did you try the example project ?

@gibrandev
Copy link

gibrandev commented Apr 20, 2020

Not working, i tried example project

  <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>

  <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>
          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
      </intent-filter>
  </service>

@Dallas62
Copy link
Collaborator

Hi @gibrandev
Can you be more precise on what is not working ?
Try with this receiver:

        <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"/>

instead of:

  <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>

Thanks

@gibrandev
Copy link

@Dallas62 i am sorry, not working same with this issues

@anisimov74
Copy link
Author

anisimov74 commented Apr 20, 2020

@Dallas62 the only change is that onNotification get called only one time when a notification is received. This callback still is not called when i press the notification.
Tried both on a simulator and a real device.
I use Firebase console to send a test notification. Not sure if it's relevant to the problem, but I see no data: {} sent by Firebase. I'm using additional options to send custom data.

Could you please point out where i can find the example project. Can't find the ref to it in docs. Thank you!

@Dallas62
Copy link
Collaborator

@anisimov74 In the example folder ;)

@anisimov74
Copy link
Author

anisimov74 commented Apr 21, 2020

@Dallas62 i tried an example project. It works with local notifications as expected. But it's only about local notification. Right?
Also tried to run the example app with rn-0.59.10. It fails to build on Android.
I'm using "react": "16.8.3", "react-native": "0.59.10". May this is the case?

@gibrandev
Copy link

@anisimov74 Is your case fixed?

@Dallas62
Copy link
Collaborator

Hi @anisimov74 @gibrandev
Sorry @581 did not see your reply,
I released a new version, can you test it ?

@gibrandev
Copy link

gibrandev commented Apr 23, 2020

@Dallas62 keep not working with this case, i have tested

@anisimov74
Copy link
Author

@Dallas62 I have the same problem with the latest version.

@dhoncrisley
Copy link

same problem here, the onNotification is called only on foreground or for local notifications.
If i press the remote notification nothing happens, only open the app.

@dhoncrisley
Copy link

dhoncrisley commented Apr 25, 2020

I also notice that there is a difference between local and remote notification. When touching the
local notification the app does not restart, it returns from where it left off. On the remote it restarts the app, as if it had opened for the first time. In addition, the floating notification and sounds do not change ...

@Dallas62
Copy link
Collaborator

Hi,
I don't understand all the issue, does onNotification called when the you send a remote notification and the app is closed ?
I tested the example project and the onNotification is called. Can you check your configuration ?

@Dallas62
Copy link
Collaborator

I tested with :

  • remote and scheduled
  • foreground
  • background
  • closed

onNotification always called.

@dhoncrisley
Copy link

with me fire onNotification on:

  • Remote on foreground:
  • local on foreground;
  • local on background;
  • local on closed;

not fire on:

  • Remote background (Open) - When touch the app appear like reopened
  • Remote background(Closed) ;

i've put the configure() on entrypoint of app root/index.js;
obs: i'm using Redux and Redux Persist
my configure function called useEffect in a component on root

function configure() {
    PushNotification.configure({
      // (optional) Called when Token is generated (iOS and Android)
      onRegister: this.onRegister, //this._onRegister.bind(this),

      // (required) Called when a remote or local notification is opened or received
      onNotification: this.onNotification, //this._onNotification,

      // ANDROID ONLY: FCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
      senderID,//from constant on module scope

      // IOS ONLY (optional): default: all - Permissions to register.
      /* permissions: {
        alert: true,
        badge: true,
        sound: true,
      }, */

      // Should the initial notification be popped automatically
      // default: true
      popInitialNotification: true,

      /**
       * (optional) default: true
       * - Specified if permissions (ios) and token (android and ios) will requested or not,
       * - if not, you must call PushNotificationsHandler.requestPermissions() later
       */
      requestPermissions: true,
    });
  }

@Dallas62
Copy link
Collaborator

Hi @dhoncrisley
I was speaking about AndroidManifest.xml
Your .configure() looks good to me.

@dhoncrisley
Copy link

my AndroidManifest.xml

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

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  <uses-permission android:name="android.permission.WAKE_LOCK" />

  <application 
    android:name=".MainApplication" 
    android:label="@string/app_name" 
    android:icon="@mipmap/ic_launcher" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:allowBackup="false" 
    android:theme="@style/AppTheme" 
    android:usesCleartextTraffic="true">
      <activity 
        android:name=".MainActivity" 
        android:label="@string/app_name" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait">

        <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="ongold" />
        </intent-filter>
      </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <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>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>

      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                  android:value="Compra Daqui!"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                  android:value="Canal de Notificações Compra Daqui"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                  android:resource="@android:color/white"/>


  

    <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:enabled="true" android:exported="false" android:grantUriPermissions="true">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
    </provider>


    
  </application>

</manifest>

@MuhammadHassanAmin
Copy link

MuhammadHassanAmin commented Apr 25, 2020

same problem onNotification does not call when I click the notification from the tray instead it reopens the app and onRegister get triggered

@Dallas62
Copy link
Collaborator

Did you set google-services.json and gradle configuration ?
https://github.com/zo0r/react-native-push-notification#if-you-use-remote-notifications

@Dallas62
Copy link
Collaborator

Can you try with the version on Master ?

@gibrandev
Copy link

@Dallas62 i have use example use react native 0.62.2, this issue is work perfect.
I use the react native 0.61.5 in my case, does it matter?

@Dallas62
Copy link
Collaborator

Hi @gibrandev the example project, run with the version on master, can you try ?

@Dallas62
Copy link
Collaborator

Can you provide updated AndroidManifest or a complete project to reproduce your issue ?
Or I will not be able to reproduce your issue...

@gibrandev
Copy link

@Dallas62 here my complete AndroidManifest

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
      android:largeHeap="true"
      android:usesCleartextTraffic="true"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_notification" />
      <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/base_color" />
      <activity
        android:name=".SplashActivity"
        android:theme="@style/SplashTheme"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity
        android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat">
      </activity>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:exported="true" />
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <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>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>

      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                  android:value="Example-Channel"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                  android:value="Super channel description"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                  android:resource="@android:color/white"/>
                  
    </application>

</manifest>

@Dallas62
Copy link
Collaborator

@Dallas62 thank you for the new release!
In the docs stated that onRegister "Called when Token is generated (iOS and Android)". I tried also the example project and this method never called. As far as I understand no user action is required to get a device token. Could you please help?

You have two options:

  • set requestPermissions: true, to true, and it will be triggered automatically
  • set requestPermissions: false, to false and call PushNotification.requestPermissions();

@Dallas62
Copy link
Collaborator

@gibrandev I'm not sure have multiple activities is good for the project,
Can you provide a minimal project that reproduce the issue ?

@gibrandev
Copy link

@Dallas62 of course, I will make it ASAP, and give the report.

@Dallas62
Copy link
Collaborator

@gibrandev Thanks ! 😃

@gibrandev
Copy link

@Dallas62 i have done testing with small project, work perfect. In my project use a "react-native-splash-screen": "^3.2.0" i think this a problem in my case

@Dallas62
Copy link
Collaborator

@gibrandev I have a project with react-native-splash-screen but I don't have a specific activity for the splash-screen, you should check the configuration of react-native-splash-screen.

@gibrandev
Copy link

@Dallas62 my code is work now 😁, my problem in AndroidManifest you can compare with my comment in top. Thank you for your atention. 🙏

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
      android:largeHeap="true"
      android:usesCleartextTraffic="true"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_notification" />
      <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/base_color" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        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.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat">
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <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>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>

      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                  android:value="Example-Channel"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                  android:value="Super channel description"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                  android:resource="@android:color/white"/>
    </application>
</manifest>

@Dallas62
Copy link
Collaborator

Nice !

@Dallas62
Copy link
Collaborator

@anisimov74 @dhoncrisley @gibrandev
So everything is fine now ? 😃

@anisimov74
Copy link
Author

anisimov74 commented Apr 29, 2020

@Dallas62 still no onRegister callback.
Please note, that i have the same situation in the example app.

Could you please take a look on my configuration?

build.gradle:

buildscript {
    ext {
      buildToolsVersion = "28.0.3"
      minSdkVersion = 16
      compileSdkVersion = 28
      targetSdkVersion = 28
      supportLibVersion = "28.0.0"

      firebaseVersion = "17.4.0"
      googlePlayServicesVersion = "16.+"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath('com.google.gms:google-services:4.3.3')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "https://www.jitpack.io" }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

settings.gradle:

rootProject.name = 'X'
include ':bugsnag-react-native'
project(':bugsnag-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/bugsnag-react-native/android')
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':@react-native-community_async-storage'
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-image-crop-picker'
project(':react-native-image-crop-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-crop-picker/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')

include ':app'
include ':react-native-eventsource'
project(':react-native-eventsource').projectDir = new File(rootProject.projectDir, '../node_modules/@huston007/react-native-eventsource/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')

include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = file('../node_modules/react-native-push-notification/android')

app/build.gradle:

apply plugin: "com.android.application"
apply from: 'versioning.gradle'

project.ext.vectoricons = [
    iconFontNames: [ 'MaterialCommunityIcons.ttf', 'FontAwesome.ttf' ]
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

import com.android.build.OutputFile


project.ext.react = [
    entryFile: "index.js",
    // whether to bundle JS and assets in debug mode
    bundleInDebug: false,
    // whether to bundle JS and assets in release mode
    bundleInRelease: true,

    // the root of your RN project, i.e. where "package.json" lives
    root: "../../"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "X"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode buildVersionCode(appVersion)
        versionName buildVersionName(appVersion)
        vectorDrawables.useSupportLibrary = true
        ndk {
            abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
        multiDexEnabled true
        missingDimensionStrategy 'react-native-camera', 'general'
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation project(':react-native-push-notification')
    implementation project(':bugsnag-react-native')
    implementation project(':react-native-svg')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-gesture-handler')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-camera')
    implementation project(':react-native-image-crop-picker')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-eventsource')
    implementation project(':react-native-device-info')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.google.firebase:firebase-analytics:17.4.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.media:media:1.0.0'
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
  from configurations.compile
  into 'libs'
}

apply plugin: 'com.google.gms.google-services'

Manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="X"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>

    <uses-sdk android:targetSdkVersion="22"/>

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:usesCleartextTraffic="true"
      android:label="@string/app_name"
      android:icon="@mipmap/yt_logo"
      android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/notification_icon" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/notification_icon_color" />

      <activity
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme"
        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=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
      </activity>

        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

        <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>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value="Example-Channel"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value="Super channel description"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
            android:resource="@color/notification_icon_color"/>

    </application>
</manifest>

MainApplication.java:

package X;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.bugsnag.BugsnagReactNative;
import com.horcrux.svg.SvgPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import org.reactnative.camera.RNCameraPackage;
import com.reactnative.ivpusic.imagepicker.PickerPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.github.jonnybgod.RNEventSource.RNEventSourcePackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import com.learnium.RNDeviceInfo.RNDeviceInfo;

import java.util.Arrays;
import java.util.List;

import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;

public class MainApplication extends Application implements ReactApplication {

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

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            BugsnagReactNative.getPackage(),
            new SvgPackage(),
            new VectorIconsPackage(),
            new RNGestureHandlerPackage(),
            new AsyncStoragePackage(),
            new RNCameraPackage(),
            new PickerPackage(),
            new LinearGradientPackage(),
            new RNEventSourcePackage(),
            new RNDeviceInfo(),
            new ReactNativePushNotificationPackage()
      );
    }

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

@anisimov74
Copy link
Author

@Dallas62 I found this in Logcat logs:

2020-04-29 19:42:07.783 1917-1928/? W/ActivityManager: Unable to start service Intent { cmp=com.example/com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService (has extras) } U=0: not found

@Dallas62
Copy link
Collaborator

With the latest version?
This service is not needed in AndroidManifest

@anisimov74
Copy link
Author

anisimov74 commented Apr 29, 2020

@Dallas62 it's the example app from the repo

"@react-native-community/push-notification-ios": "^1.1.1",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-push-notification": "git+https://git@github.com/zo0r/react-native-push-notification.git"

@Dallas62
Copy link
Collaborator

There is a new release 3.3.0, this should be better

@anisimov74
Copy link
Author

anisimov74 commented Apr 29, 2020

@Dallas62 I tried 3.3.0 in my app and posted my configuration above ^^. I have the same problem :(

@Dallas62
Copy link
Collaborator

Did you set this:

  requestPermissions: true,

@anisimov74
Copy link
Author

anisimov74 commented Apr 29, 2020

@Dallas62 sure. I also tried to call it manually as you suggested with PushNotification.requestPermissions()

PushNotification.configure({
      onRegister: function(t) {
        console.log('token generated', t);
      },
      onNotification: onNotification,
      senderID: 'XXXXXXXXXXX',
      permissions: {
        alert: true,
        badge: true,
        sound: true,
      },
      popInitialNotification: true,
      requestPermissions: true,
    });

@Dallas62
Copy link
Collaborator

Really strange,
Did you remove:

<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

@anisimov74
Copy link
Author

@

Really strange,
Did you remove:

<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

Updated as described in the doc

<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>

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value="X"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value="X"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
            android:resource="@color/notification_icon_color"/>

@Dallas62
Copy link
Collaborator

senderID is not needed anymore but it's not the problem, did you set the google-service.json of Firebase ?
I don't get it, it's like PushNotification.configure is not called 😕

@anisimov74
Copy link
Author

senderID is not needed anymore but it's not the problem, did you set the google-service.json of Firebase ?
I don't get it, it's like PushNotification.configure is not called 😕

google-service.json is set, PushNotification.configure is called.
Could you please check the example project. Does it work properly for you?

@Dallas62
Copy link
Collaborator

Capture d’écran 2020-04-30 à 10 48 02

  • First console.log comes from PushNotification.configure.
  • Second one from the click on Request Permissions.

Here the test commands:

  • Uninstall the application from the device.
# react-native-push-notification on git:master o [10:42:51] 
$ cd example 

# react-native-push-notification/example on git:master o [10:43:04] 
$ rm -rf node_modules 

# react-native-push-notification/example on git:master o [10:43:20] 
$ cat package.json 
{
  "name": "example",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/push-notification-ios": "^1.1.1",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-push-notification": "git+https://git@github.com/zo0r/react-native-push-notification.git"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "@babel/runtime": "^7.9.2",
    "@react-native-community/eslint-config": "^1.0.0",
    "babel-jest": "^25.3.0",
    "eslint": "^6.8.0",
    "jest": "^25.3.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

# react-native-push-notification/example on git:master o [10:43:30] 
$ yarn
yarn install v1.12.3
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-native > react-devtools-core > ws@7.2.5" has unmet peer dependency "bufferutil@^4.0.1".
warning "react-native > react-devtools-core > ws@7.2.5" has unmet peer dependency "utf-8-validate@^5.0.2".
warning "@react-native-community/eslint-config > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning "jest > @jest/core > jest-config > jest-environment-jsdom > jsdom@15.2.1" has unmet peer dependency "canvas@^2.5.0".
[4/4] 📃  Building fresh packages...
success Saved lockfile.
✨  Done in 49.21s.

# react-native-push-notification/example on git:master o [10:45:17] 
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 985 file(s) to forward-jetify. Using 16 workers...
info Starting JS server...
info Installing the app...
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

> Task :react-native-push-notification:compileDebugJavaWithJavac

> Task :app:stripDebugDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:installDebug
10:46:01 V/ddms: execute: running am get-config
10:46:02 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
10:46:02 V/ddms: execute: returning
Installing APK 'app-debug.apk' on 'Pixel_3a_API_29(AVD) - 10' for app:debug
10:46:02 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'
10:46:02 D/Device: Uploading file onto device 'emulator-5554'
10:46:02 D/ddms: Reading file permision of react-native-push-notification/example/android/app/build/outputs/apk/debug/app-debug.apk as: rw-r--r-
-
10:46:02 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
10:46:03 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
10:46:03 V/ddms: execute: returning
10:46:03 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
10:46:03 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
10:46:03 V/ddms: execute: returning
Installed on 1 device.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 18s
48 actionable tasks: 27 executed, 21 up-to-date
info Connecting to the development server...
8081
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.example/.MainActivity }

@MarcoStb1993
Copy link

Unfortunately, I am facing the same issue as @anisimov74 after "upgrading" from master to 3.3.1. So I went back to the example and added the google-services.json as well as replacing the react-native-push-notification version in package.json with "3.3.1". Then I ran npm install and started the app, nothing was logged and no register token is shown.

I saw that implementation 'com.google.firebase:firebase-analytics:17.3.0' was missing in android/app/build.gradle. So, I added it. But still the same, the app is not registered with firebase.

@Dallas62
Copy link
Collaborator

Dallas62 commented May 4, 2020

Thanks for the feedback, I think the initial issue is closed, the issue you discribed @MarcoStb1993 looks like:
#1380
Can you copy you comment on this issue ?
I will look into it ASAP.

@Dallas62 Dallas62 closed this as completed May 4, 2020
@MarcoStb1993
Copy link

@Dallas62 I opened a new issue since I think the one you mentioned describes a different problem. I hope this is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants