EXPO. Notifications do not popup - android

"expo": "^39.0.0" / Library - expo-notifications.
Since moving to the new API, I have been facing various problems. I fixed problems with the icon, with receiving a notification in apk, with handlers, and now I could not find an answer to this question.
I have 3 phones Samsung Galaxy S9+ with Android 10, Xiaomi Redmi 4x with Android 7.12 N2G47H MIUI 10 Global 9.6.27 and Xiaomi Redmi Note 4 Global Android 7.0 nrd90m MIUI global 11.0.2.
Samsung Galaxy S9+. With my current config i receive notification
excellent as it should be:
Vibration +
Sound +
Popup when notification comes +
All this come from the box, i do not need to ask permissions or something like that.
Xiaomi Redmi 4x and Xiaomi Redmi Note 4.
With my current config i have problems:
Vibration - do not work both in both published and apk(standalone) versions
Sound +
Popup when notification comes +
AND THE MAIN PROBLEM: All this DO NOT come from the box, I need to manually give permission for notifications to pop up, sound, etc.
My app.json :
{
"expo": {
"name": "qwert",
"slug": "qwert",
"version": "1.1.2",
"orientation": "portrait",
"icon": "./src/assets/images/logo1024.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"privacy": "unlisted",
"splash": {
"image": "./src/assets/images/splashScreen.png",
"resizeMode": "contain",
"backgroundColor": "#f1f0f0"
},
"android": {
"package": "com.qwert.app",
"googleServicesFile": "./google-services.json",
"versionCode": 1,
"useNextNotificationsApi": true
},
"notification": {
"icon": "./src/assets/images/VIAicon96.png",
"color": "#8edcd5",
"androidMode": "collapse"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"web": {
"favicon": "./assets/images/favicon.png"
},
"description": ""
}
}
My permissions/configs:
import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
import { Platform } from 'react-native';
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
export const registerForPushNotificationsAsync = async () => {
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') {
console.log('Failed to get push token for push notification!');
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
} else {
console.log('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',
});
}
// eslint-disable-next-line consistent-return
return token;
};
Also, place where use all this:
useEffect(() => {
const handleNotification = async () => {
await getPermitsAndIntegrateIntoApp(store); // works great
};
const setPersistDataToStore = async () => {
const EXPO_PUSH_TOKEN = await registerForPushNotificationsAsync();
const qwertyyy = await getConfig(Constants.deviceId, EXPO_PUSH_TOKEN);
store.setQwerrt(config.destinations);
};
setPersistDataToStore();
Notifications.addNotificationReceivedListener(handleNotification);
return () => Notifications.removeAllNotificationListeners();
}, [store]);
On all 3 phones I have a logic for handling notifications ( send request, updates store, and updates screen on my app). It works correct.
How to automatically configure the permission to show push notifications? How to enable vibration on Xiaomi?

Finally i found an answers.
https://github.com/expo/expo/issues/8556 tells us that
And that
Permissions.askAsync not working as expected tells us how to let user set permissions to notifications.
And i still do not know why Xiaomi do not vibrate......

I have Xiaomi Redmi 6A, and with default configuration from examples in Expo documentation I received only vibration on notification. I have to manually turn on pop up (floating) and sound for default channel. Only after that notifications began to work as expected.

Related

expo-auth-session - Two app options on return to app

SDK Version: 43.0.0
Platforms(Android/iOS/web/all): Android
Hello, I'm using expo-auth-session in the managed workflow to collect Instagram user data through its official API, it's working fine on the development environment (through the "expo run:android" command), but once a build APK is created when the user makes the authorization process and the redirect starts there is a popup asking “Open with” and two options for my app, the first one works perfectly the second one goes back to the app but does nothing, I didn't test on IOS.
Here is the image that represent it:
Click here to see
When I was developing I tried to do the google sign-in process but was stuck in the same error, partially resolved by implementing google native sign-in. I verified my schemes in app.json but didn`t identify wrong on it, as follows:
app.json:
{
"expo": {
"name": "Secreet",
"slug": "secreet",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"scheme": "com.davidtmiranda.secreet",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"usesAppleSignIn": true,
"bundleIdentifier": "com.davidtmiranda.secreet",
"googleServicesFile": "./GoogleService-Info.plist",
"config": {
"googleSignIn": {
"reservedClientId": "com.googleusercontent.apps.--------------------"
}
}
},
"android": {
"versionCode": 1,
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.davidtmiranda.secreet",
"googleServicesFile": "./google-services.json"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
also, my authSession code looks like this:
webBrowser.maybeCompleteAuthSession();
const useProxy = Platform.select({ web: false, default: true });
const client_id = ---;
const redirect_uri = "https://auth.expo.io/#davidtmiranda/secreet";
const scope = "user_profile";
const site =
"https://api.instagram.com/oauth/authorize?client_id=" +
client_id +
"&redirect_uri=" +
redirect_uri +
"&scope=" +
scope +
"&response_type=code&state=1";
const discovery = { authorizationEndpoint: site };
const [request, response, promptAsync] = useAuthRequest(
{
redirectUri: makeRedirectUri({
useProxy,
native: redirect_uri,
}),
scopes: [scope],
clientId: String(client_id),
},
discovery
);
useEffect(() => {
if (response?.type === "success") {
...
}
}, [response]);
function GetInstagramID() {
return promptAsync({
useProxy,
});
}
Any suggestions about how to solve this problem? I believe it is schema-related but could not identify what is wrong.
Maybe you can try to remove scheme in the app.json
"scheme": "com.davidtmiranda.secreet",
and it will change appAuthRedirectScheme in the android/app/build.gradle
manifestPlaceholders = [appAuthRedirectScheme: 'com.davidtmiranda.secreet']
It solves my issue.

React Native Expo - Push Notification for android

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

Android APK not working properly after build using Expo React Native

I've been working on an app, and I have been using both the Android emulator and my Android device for testing using Expo.
It works great, everything goes perfect. However, I just built an Android APK (I executed expo build:android), and I can see the login of my app, but after introducing credentials, it kinda shows like it closes the app and then restores it, but now it keeps showing just a blank screen.
Here is a gif showing you exactly what happens.
https://giphy.com/gifs/hdtXNeM2s5Dx7FnbNJ
Also, here's the code of my App.js, which works showing the <AuthNavigator /> (The login screen), but it stops working when a user is set and then <AppNavigator /> does not appear.
import React, { useState } from "react";
import { StyleSheet } from "react-native";
import { NavigationContainer } from "#react-navigation/native";
import { AppLoading } from "expo";
import AppNavigator from "./app/navigation/AppNavigator";
import AuthNavigator from "./app/navigation/AuthNavigator";
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
export default function App() {
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) setUser(user);
};
if (!isReady) {
return (
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)} />
);
}
return (
<AuthContext.Provider value={{ user, setUser }}>
<NavigationContainer>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</AuthContext.Provider>
);
}
Also my app.json, just in case it's needed:
{
"expo": {
"name": "Agro-Mobile",
"slug": "Agro-Mobile",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./app/assets/icon.png",
"splash": {
"image": "./app/assets/splash.png",
"resizeMode": "cover",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
"android": {
"package": "com.smartbase.agrocognitive",
"versionCode": 1
},
"web": {
"favicon": "./app/assets/favicon.png"
},
"description": ""
}
}
In app.json you need change:
"android": {
"package": "com.smartbase.agrocognitive",
"versionCode": 1
for this
"android": {
"package": "com.agrocognitive.agrocognitive",
"versionCode": 1
in other words you need only change the name of company for the name of your app, make sure use only lowercase characters without simbol. The folder that your create have the same name of your app. And for other people delete any commentary in App.js.
This works for me in bluestacks emulator and in my phone running apk file
I hope help you

How to make FCM as quick as possible on both iOS and Android?

I am trying to speed up notifications delivery on firebase notifications.
Because sometimes it might take 10 seconds to get the notification.
Currently I am using this message to send notification with admin.messaging().send(message).
const message = {
notification: {
title: 'Immediate Notification',
body: 'Important Message',
},
data: {
title: 'data',
body: 'some data'
},
android: {
ttl: 1000,
"notification": {
"sound": "default"
}
},
apns: {
headers: {
"apns-expiration": "1000",
},
payload: {
aps: {
badge: 1,
"sound": "default"
},
},
},
};
I am not sure if the speed will increase.
Need Clerification:-
1) If I put "apns-priority": "10" for iOS ? and priority high for android ? Something like this:
headers: {"apns-priority": "10"}
"android":{"priority":"high"},
2) If I set Time To Live to 0 ? ttl:0 and "apns-expiration": 0
3) If I don't send anything in data object ?
Or maybe there are any other way to speed them up ?

Cannot get notifications when my Ionic 3 app is in foreground ( For iOS ), Android works fine

The payload I am sending is fine, searched for this a lot, Android foreground notifications are working fine. And in iOS, when the app is in the background or app is closed, I receive notification correctly.
But when the app is in the foreground, I don't get the notification, neither the .on('notification', ()=>{}) is triggered. Any ideas would be helpful.
Already gone through a lot of stuff.
const options: PushOptions = {
android: {},
ios: {
"sound": "true",
"alert": "true",
"badge": "true",
"clearBadge": "true"
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification')
.subscribe((notification: any) => {
// {
// additionalData: {
// typeData: {}//Sent from server,
// coldstart: "false",
// foreground: "false"
// }
// }
let alertme = this.alert.create({
title : "GOT NOTIFIED",
subTitle : JSON.stringify( notification ),
buttons : [{
text: 'Ok',
handler: () => {
}
}]
});
alertme.present();
});

Categories

Resources