LuckyLuke
LuckyLuke

Reputation: 1054

Expo android app, PushNotifications doesn't work in standalone apk?

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

Upvotes: 10

Views: 10184

Answers (5)

Melvin
Melvin

Reputation: 143

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)

Upvotes: 1

Jaccon
Jaccon

Reputation: 79

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

Upvotes: 0

cangokceaslan
cangokceaslan

Reputation: 482

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

Upvotes: 9

Leon
Leon

Reputation: 6059

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

Upvotes: 2

LuckyLuke
LuckyLuke

Reputation: 1054

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

Upvotes: 24

Related Questions