Разрешение уведомления Android и фоновые задачиAndroid

Форум для тех, кто программирует под Android
Anonymous
Разрешение уведомления Android и фоновые задачи

Сообщение Anonymous »

На устройствах Android 14 уведомления никогда не появляются, и фоновая синхронизация перестает работать после того, как приложение переходит на фоновые данные. Государства разрешения показывают, как предоставлено, но ничего не работает. Получение «Фоновое выполнение не разрешено» в журналах. < /P>
import { PermissionsAndroid, AppState } from 'react-native';
import PushNotification from 'react-native-push-notification';
import BackgroundJob from 'react-native-background-job';

const [notificationEnabled, setNotificationEnabled] = useState(false);
const [backgroundTaskActive, setBackgroundTaskActive] = useState(false);

const initializeApp = async () => {
await requestNotificationPermission();
await startBackgroundSync();

if (notificationEnabled && backgroundTaskActive) {
schedulePeriodicNotifications();
}
}

const requestNotificationPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
);

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
setNotificationEnabled(true);

PushNotification.configure({
onNotification: function(notification) {
console.log('Notification received:', notification);
},
requestPermissions: Platform.OS === 'ios'
});
}
} catch (err) {
console.warn(err);
}
}

const startBackgroundSync = async () => {
BackgroundJob.start({
jobKey: 'myJob',
period: 30000, // 30 seconds
requiredNetworkType: 'any'
});

setBackgroundTaskActive(true);
}

const schedulePeriodicNotifications = () => {
PushNotification.localNotificationSchedule({
title: "Data Sync Complete",
message: "Your data has been synchronized",
date: new Date(Date.now() + 60 * 1000), // 1 minute from now
repeatType: 'minute'
});
}


Подробнее здесь: https://stackoverflow.com/questions/797 ... ound-tasks

Вернуться в «Android»