Android standalone app doesn't get Expo Push Notification

#1

Hello
First please understand me my English is rather poor.

I have a issue for using Expo Push Notification.

In expo app, expo push notification work well.
But when I build android standalone app and install on my device, then doesn’t work.

It doesn’t get expopushnotificationtoken, that is, getExpoPushTokenAsync() does not get expo push notification token.

First it doesn’t get token but few days after it get token although code is not changed. But next day it doesn’t work again.

Following is my code:

	if (!Expo.Constants.isDevice) {
	  return;
	}
	let { 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;
	}
	try {
		let value = await Notifications.getExpoPushTokenAsync();
                    alert(value);
		// Send this to a server
	} catch (error) {
		alert(error);
	}

Notifications.getExpoPushTokenAsync() function doesn’t return anything. So alert(value) doesn’t work.

my app.json file is following:
{
“expo”: {
“name”: “neighborhood”,
“description”: “This project is really great.”,
“slug”: “neighborhood”,
“privacy”: “public”,
“sdkVersion”: “30.0.0”,
“platforms”: [“ios”, “android”],
“version”: “1.0.0”,
“orientation”: “portrait”,
“icon”: “./src/assets/images/icon.png”,
“notification”: {
“icon”: “./src/assets/images/notification_icon.png”,
“color”: “#000000
},
“updates”: {
“fallbackToCacheTimeout”: 0
},
“assetBundlePatterns”: [
“**/*”
],
“ios”: {
“supportsTablet”: true,
“bundleIdentifier”: “com.waterflower.safteyzone3”

},
"android": {
  "package": "com.waterflower.safteyzone",
  "googleServicesFile": "./google-services.json"
}

}
}

my react native information is following:
Environment:
OS: macOS High Sierra 10.13.4
Node: 10.11.0
Yarn: Not Found
npm: 6.4.1
Watchman: 4.9.0
Xcode: Xcode 9.4 Build version 9F1027a
Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz => 0.55.4

my expo version 2.2.4(expo --version).

I’m very happy to hear your advance.

Thanks.

2 Likes
#2

Same…

#3

I’m also facing the same Issue. It’s working fine in Dev. But when App is built Unable to fetch the Token (getExpoPushTokenAsync). Unable to Alert the Token.

/* Lib Imports */
import {Permissions, Notifications} from 'expo';

const create = () => {
  const registerForPushNotificationsAsync = async () => {
    alert("registerForPushNotificationsAsync")
    const {status: existingStatus} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    let finalStatus = existingStatus;

    if (existingStatus !== 'granted') {
      const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }
    // Stop here if the user did not grant permissions
    if (finalStatus !== 'granted') {
      alert("finalStatus !== granted")
      return "";
    }
    // Get the token that uniquely identifies this device
    try {
      let token = await Notifications.getExpoPushTokenAsync();
      alert(token);
      return token;
    } catch (err) {
      alert("Error", err)
      console.log("Error", err);
    }

  }
  return {registerForPushNotificationsAsync}
}
export default {create}

“sdkVersion”: “30.0.0”,
“expo”: “^30.0.0”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz”,

#4

Same here. Seems to be working on IOS though.

#5

It’s happening on my Android too, I believe it’s a problem in building the app. I returned a version in git (version I generated in a build) and it did not work.
It is very sad that we develop the application using the expo and realize that the build is unstable.

“dependencies”: {
“axios”: “^0.18.0”,
“expo”: “^29.0.0”,
“expo-cli”: “^2.1.3”,
“expokit”: “1.5.0”,
“lodash”: “^4.17.11”,
“moment”: “^2.22.2”,
“native-base”: “^2.6.0”,
“react”: “16.3.1”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz”,
“react-native-animatable”: “^1.3.0”,
“react-native-collapsible”: “^0.13.0”,
“react-native-datepicker”: “^1.7.2”,
“react-native-elements”: “^0.19.1”,
“react-native-material-design-searchbar”: “^1.8.0”,
“react-native-signalr”: “^1.0.6”,
“react-native-sqlite-storage”: “^3.3.6”,
“react-native-vector-icons”: “^4.6.0”,
“react-navigation”: “^2.9.3”
},

#6

@adamjnav Could you please look into this issue. Unable to Fetch the Token when the App is build. As it works fine when we use it in Dev in Expo App.

#7

Mine worked, and stopped suddenly.

Now the request takes too long and does not return an error.

“dependencies”: {
“base-64”: “^0.1.0”,
“base64-js”: “^1.3.0”,
“crypto-js”: “^3.1.9-1”,
“exp”: “^57.2.1”,
“expo”: “^30.0.0”,
“expo-server-sdk”: “^3.0.1”,
“moment”: “^2.22.2”,
“native-base”: “^2.7.1”,
“react”: “16.3.1”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz”,
“react-native-action-button”: “^2.8.4”,
“react-native-actionsheet”: “^2.4.2”,
“react-native-cli”: “^2.0.1”,
“react-native-color-palette”: “^2.0.1”,
“react-native-datepicker”: “^1.7.2”,
“react-native-device-info-2”: “^0.1.1”,
“react-native-elements”: “^0.19.1”,
“react-native-keyboard-aware-scroll-view”: “^0.7.2”,
“react-native-maps”: “^0.21.0”,
“react-native-masked-text”: “^1.7.2”,
“react-native-material-textfield”: “^0.12.0”,
“react-native-router-flux”: “^4.0.0-beta.40”,
“react-native-scripts”: “^1.14.0”,
“react-native-select-multiple”: “^1.2.0”,
“react-native-vector-icons”: “^4.6.0”,
“react-timer-mixin”: “^0.13.4”,
“rn-pdf-reader-js”: “^0.1.7”,
“sort-by-distance”: “^1.0.1”
},
“devDependencies”: {
“jest-expo”: “^30.0.0”
}

#8

Same here, something wrong with expo servers?
why no throw error when timeout i need to handle manually?

Note: the same code in iOS works as expected,

we need some feedback from expo team (@Expo)

Thanks !!

#9

We don’t have any info on this but you could try adding a Promise.race timeout.

#10

Hi @ide, this is very strange here a topic from github:

for now I will make a promise.race, but this may be for devices that request the token for the first time?

#11

Did you guys set up your FCM API keys? Our standalone app is able to receive Push Notifications on both platforms with no issues.

#12

@ide Still there is an issue with EXPO SDK 31. Please check the below issue.

closed #13

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.