0

Im trying to send push notification to an android device using the expo push notification tool, (It is working for iOS) but it doesn't work, I have added a firebase project with a separate android app, the google-service.json, and ran the expo push:android:upload --api-key . Is there something missing ?

Im using a managed workflow SDK 39

This is the code which I have used and it works perfectly for iOS

getting the expo push notification code

async function registerForPushNotificationsAsync() {
  let token;
  if (Constants.isDevice) {
    const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      
      return;
    }
    token = (await Notifications.getExpoPushTokenAsync()).data;
    let uid;
    firebase.auth().signInAnonymously()
      .then(() => {
        uid = firebase.auth().currentUser.uid;
      })
      .then(() => {
        db.collection('users').doc(uid).get()
            .then(function(doc) {
                if (doc.exists) {
                    db.collection('users').doc(uid).update({
                      expoPushToken: token,
                      'last use date': new Date().toISOString().slice(0,10),
                      'region': Localization.region
                    })
                } else {
                    db.collection('users').doc(uid).set({
                      expoPushToken: token,
                      'last use date': new Date().toISOString().slice(0,10),
                      'region': Localization.region
                    })
                }
            })
      })
      .catch(() => console.log('ERROR'))

  } else {
    alert('Must use physical device for Push Notifications');
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
    });
  }

  return token;
}

app.json

"android": {
      "useNextNotificationsApi": true,
      "googleServicesFile": "./google-services.json",
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "com.NAME.NAME",
      "versionCode": 3
    },
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Aakash Rathee
  • 523
  • 3
  • 17

0 Answers0