Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 630
LuckyLuke Avatar asked Jan 25 '20 17:01

LuckyLuke


3 Answers

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

like image 118
LuckyLuke Avatar answered Nov 02 '22 18:11

LuckyLuke


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

like image 22
Leon Avatar answered Nov 02 '22 17:11

Leon


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

like image 29
cangokceaslan Avatar answered Nov 02 '22 17:11

cangokceaslan