10

I am facing a problem, when I am running an app through expo client app, PushNotifications works. But if I am building a standalone .apk, I need to install expo client, in order to get pushtoken. And, when expo client is not turned on, I cannot get pushtoken. So my customer needs to install 2 apps. One is mine, built standalone .apk, and other is expo client. It is tedious flow..

LuckyLuke
  • 1,028
  • 2
  • 14
  • 28

5 Answers5

24

I was able to fix expo push notifications in my project. It was my own fault. The problem was this, even documentation provides solution: enter image description here So I created an account with Firebase, then I attached new project. Then I ran this command:

expo push:android:upload --api-key <Server key>

You can get server key from this section: enter image description here

It will look something like this:

XXXSdasx665:APA91bFL2342342342342342342342RxDAUbCOP0IL32etVueLhnLtoFErsqHBhjW-SRPSZGdU18BBIltUx7Wm234234234sxdxzcasdSElRyTEdMR7vmLJHgVvbOGx-0-SWDasdzxzxzx

This helped me to fix the issue I was having. Hopes it will help someone too.

This is an app.json file:

{
  "expo": {
    "name": "workero",
    "slug": "workero",
    "privacy": "public",
    "sdkVersion": "36.0.0",
    "platforms": ["android"],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "package": "com.workero.apper",
      "googleServicesFile": "./google-services.json"
    }
  }
}

LuckyLuke
  • 1,028
  • 2
  • 14
  • 28
  • Do you get it properly now ? As in does the notification pop up ? – Muljayan Feb 02 '20 at 02:54
  • When I tested it, it worked correctly, also people that are using an application don't complain about it since I fixed it. Notification was pop-ing up – LuckyLuke Feb 02 '20 at 11:51
  • Oh, Its not popping up for me :/ but in app im detecting the notification coming. Did you set up any special permissions ? Also do you have to do any extra steps in app.json – Muljayan Feb 02 '20 at 12:32
  • I have attached my app.json file above. Also try to start an app and then send push notification. When using expo it was strange that push notifications was not popping up when the app was off. I tried to turn it off and after using firebase it seemed to pop up even when the app is turned off. :) – LuckyLuke Feb 02 '20 at 12:45
  • Oh thanks for the app.json. My file looks similar too. I uploaded the server key `expo push:android:upload --api-key ` too. I have this component and passed the data received and it actually detects the notification and shows it in the but its not popping up on the top. – Muljayan Feb 02 '20 at 18:04
  • Thank you <3 <3 <3 <3 <3 <3 – Octaviotastico Oct 08 '20 at 17:43
9

This issue occurs after SDK 38. You can solve the issue with simple steps. Firebase Cloud Messaging is required for all managed and bare workflow Android apps made with Expo, unless you're still running your app in the Expo client. To set up your Expo Android app to get push notifications using your own FCM credentials. You basically need to create a Firebase account and follow the steps.

  1. If you have not already created a Firebase project for your app, do so now by clicking on Add project in the Firebase Console.

  2. In your new project console, click Add Firebase to your Android app and follow the setup steps. Make sure that the Android package name you enter is the same as the value of android.package in your app.json.

  3. Download the google-services.json file and place it in your Expo app's root directory. In your app.json, add an android.googleServicesFile field with the relative path to the google-services.json file you just downloaded. If you placed it in the root directory, this will probably look like

         { 
    
               "android":{ 
                    "googleServicesFile": "./google-services.json",
                    "useNextNotificationsApi":true,
                }
    
    
         }
    

"useNextNotificationsApi":true are also required. Finally, make a new build of your app by running expo build:android. After these step you need to push your api key to expo server.

  1. In order for Expo to send notifications from our servers using your credentials, you'll need to upload your secret server key. You can find this key in the Firebase Console for your project:
  2. At the top of the sidebar, click the gear icon to the right of Project Overview to go to your project settings.
  3. Click on the Cloud Messaging tab in the Settings panel.
  4. Copy the token listed next to Server key.
  5. Run expo push:android:upload --api-key <your-token-here> , replacing <your-token-here> with the string you just copied. It will store your token securely on expo servers, where it will only be accessed when you send a push notification.

This steps will help you push notifications through expo server sdk or through the expo push api ExpoPush Api. (FCM is not enabled in IOS for now.)

cangokceaslan
  • 467
  • 1
  • 5
  • 12
  • 1
    Thank u so much for this great explanation. What i was missing is the last step, sending server key to expo server. BTW useNextNotificationApi : true is not needed. – Irfan wani Jan 03 '22 at 09:45
  • This answer helped me. Thank you! FYI to anyone else struggling to get push notifications on Android to work, the expo docs relating to this procedure a slightly more extensive and can be found here: https://docs.expo.dev/push-notifications/using-fcm/ – huwiler Dec 07 '22 at 20:25
2

For anyone else, for listeners in managed workflow make sure to set

"useNextNotificationsApi": true in expo.android in your app.json from the directions here

enter image description here

Leon
  • 5,701
  • 3
  • 38
  • 38
1

Guys if you don't see the server token you see that

this is from expo:

Note: Server Key is only available in Cloud Messaging API (Legacy), which may be Disabled by default. Enable it by clicking the 3-dot menu > Manage API in Google Cloud Console and follow the flow there. Once the legacy messaging API is enabled, you should see Server Key in that section.

the token don't is API de Firebase Cloud Messaging (V1)

the token is API de Cloud Messaging (heredada)

Melvin
  • 73
  • 5
0

For me im just put the "useNextNotificationsApi":true in app.json and the push notification messages working fine

Jaccon
  • 79
  • 1
  • 1
  • 6