question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] onRegister not called, no permissions requested

See original GitHub issue

Hey guys, I’ve been trying to get this working for quite a while now, but the onRegister callback never seems to get called, no matter what configuration I try.

I’m using FCM with the following settings:

top-level build.gradle

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "15.0.1"
        androidMapsUtilsVersion = "0.5+"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.0.2'
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

AndroidManifest

    <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" />
    <permission
       android:name="${applicationId}.permission.C2D_MESSAGE"
       android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />

...

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

and my PushNotification config

PushNotification.configure({
    onError: function(e) {
      console.log(e)
    },
    onRegister: function(token) {
      token.os = Platform.OS === 'ios' ? 'ios' : 'android'
      api.registerDevice(token)
    },

    onNotification: function(notification) {
     // console.log(notification)

     if (Platform.OS === 'ios') notification.finish(PushNotificationIOS.FetchResult.NoData)
    },

    senderId: SENDER_ID,
    permissions: {
     alert: true,
     badge: true,
     sound: true
    },

    popInitialNotification: true,
    requestPermissions: true
  })

Everything works well on iOS, and local notifications are working for android.

The problem I am facing is that onRegister never gets called on android (on device and on emulator) which means that there is no way for me to send remote push notifications.

I am hoping someone can help me solve this issue, or at the very least point me towards methods for debugging why it may not be called.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:23

github_iconTop GitHub Comments

11reactions
martingaloviccommented, Nov 2, 2018

[Solved my problem with crash]

Fix was basically to set com.google.android.gms:play-services-gcm and com.google.firebase:firebase-messaging to same version

so my app/build.gradle looks like:

dependencies {
   // ...
   compile ("com.google.android.gms:play-services-gcm:12.0.1") {
        force = true
    }
    compile ("com.google.firebase:firebase-messaging:12.0.1") {
        force = true
    }
}

https://github.com/rebeccahughes/react-native-device-info/issues/463#issuecomment-413313038

1reaction
haiflivecommented, May 28, 2020

on my android device problem was solved to install Google Play Services

also no any error in onError: function(e) {

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - Why isn't a device token being generated?
I can get a local notification to fire on load, and onNotification is being called upon interaction, but no token. I'm not sure...
Read more >
react-native-push-notification - npm
React Native Local and Remote Notifications for iOS and Android ... token (android and ios) will requested or not, * - if not,...
Read more >
Step by Step guide for Implementing Push Notifications in iOS ...
Specified if permissions (ios) and token (android and ios) will requested or not,. * - if not, you must call PushNotificationsHandler.
Read more >
How to use the react-native-push-notification.configure ... - Snyk
To help you get started, we've selected a few react-native-push-notification.configure examples, based on popular ways it is used in public projects.
Read more >
Push Notifications - QuickBlox Documentation
Push Notifications provide a way to deliver some information to a user while they are not using your app actively. The following use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found