I’m trying to get basic local notifications to work in a bare-minimum app. It works just fine in the expo client, but when I try to run it in a Galaxy Nexus API 28 emulator in Android Studio with yarn react-native run-android
I get this exception when pressing the “Press to Send Notification” button:
LOG Running "main" with {"rootTag":1}
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: null is not an object (evaluating '_ExponentNotifications.default.presentLocalNotification')
presentLocalNotificationAsync$@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:109860:79
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26262:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26438:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26262:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26338:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26348:21
tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27618:16
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27719:27
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31173:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31209:19
callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:31428:33
callImmediates@[native code]
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3238:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3015:34
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3221:15
flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3014:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
This is my App.js
import React from 'react';
import { Text, View, Button, Vibration, Platform } from 'react-native';
import { Notifications } from 'expo';
export default class AppContainer extends React.Component {
componentDidMount() {
Notifications.createChannelAndroidAsync(
"test1", {name: "test1 name", priority: "max"},
);
}
sendPushNotification() {
const notification = {
title: "My title NEW",
body: "My body",
android: {
channelId: "test1",
},
};
Notifications.presentLocalNotificationAsync(notification);
}
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'space-around',
}}>
<Button title={'Press to Send Notification'} onPress={() => this.sendPushNotification()} />
</View>
);
}
}
This is my package.json
{
"main": "index.js",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"web": "expo start --web",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"expo": "~37.0.3",
"expo-notifications": "^0.1.2",
"expo-updates": "~0.1.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "~0.61.5",
"react-native-gesture-handler": "~1.6.0",
"react-native-reanimated": "~1.7.0",
"react-native-screens": "~2.2.0",
"react-native-unimodules": "~0.9.0",
"react-native-web": "~0.11.7"
},
"devDependencies": {
"@babel/core": "~7.9.0",
"babel-jest": "~25.2.6",
"jest": "~25.2.6",
"react-test-renderer": "~16.9.0"
},
"jest": {
"preset": "react-native"
},
"private": true
}