invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.88k stars 228 forks source link

Notifications are not coming in Android 12 version #967

Closed ReZuBaa closed 9 months ago

ReZuBaa commented 10 months ago

There is a reminder in the application, when I set the reminder, notifications in Android 12 version send a reminder notification while the program is running in the background. However, if the program is closed, the notification does not come. I tested the application on Android 10 11 12 13 14. I only encounter this problem on Android 12. What could be the reason? Thank you in advance for your help.

react native 0.71.7
 @notifee/react-native": "7.8.2"

available codes :

import React, { forwardRef, memo, useCallback,useState, useEffect } from 'react' import { Text, View,TextInput,Platform,Button ,TouchableOpacity} from 'react-native' import DateTimePicker from '@react-native-community/datetimepicker'; import notifee, { TimestampTrigger, TriggerType,AndroidImportance, AndroidNotificationSetting } from '@notifee/react-native'; import { AlarmSvg } from '@/Assets/Svg' import { Post,ShareType, Story} from '@/Models' import { AppFonts, Colors,screenHeight, XStyleSheet } from '@/Theme' import { isAndroid, isIOS } from '@/Utils' import { homeStore, diaLogStore} from '@/Stores' import { showMessage, hideMessage } from "react-native-flash-message"; import { useLocalObservable } from 'mobx-react-lite' import { useTranslation } from 'react-i18next' import { KeyboardSpacer} from '.' import AppBottomSheet from './AppBottomSheet' import Box from './Box' import { screenWidth } from '../Theme';

interface ShareBottomSheetProps { lengi:number data: Post & Story type: ShareType onClose: (leng:number) => void page:string }

const ReminderComponent = forwardRef( ({page="", lengi,data, onClose, type = ShareType.Post }: ShareBottomSheetProps, ref) => {

console.log(23112,data.alarm,new Date().getTime())
const [startdate, setstartDate] = useState(new Date());
const [date, setDate] = useState(startdate);
const [time, setTime] = useState(startdate);
const [change, setchange] = useState(false);
const [showDatePicker, setShowDatePicker] = useState(false);
const [showTimePicker, setShowTimePicker] = useState(false);
const [title, setTitle] = useState(""); 
const [body, setBody] = useState(""); 
const [who, setwho] = useState(data.alarm?.length?true:false); 
const [deletecancel, setdeletecancel] = useState(false);

const { t } = useTranslation()

const getdata = () => { let tt = ""; let tt1 = "";

// 'medias' alanı ve içeriklerini kontrol et
if (data?.medias?.[0]?.texts?.[0]?.[0]?.text) {
  tt = data.medias[0].texts[0][0].text;
}

if (data?.subtitle?.length > 0) {
  tt1 = data.subtitle[0].text;
} 

else if (data?.details?.length > 0 && data.details[0]?.text) {
  tt1 = data.details[0].text;
}

setTitle(tt);
setBody(tt1);

};

const state = useLocalObservable(() => ({

})) const _onClose = useCallback(() => {

onClose && onClose()

}, [])
const cancelDelete =useCallback( async(notificationId:string) =>{ diaLogStore.showDiaLog({ title: t("createPost.delete_Create_Reminder"),

   showCancelButton: true,
  onClose:()=>{ 

      console.log(2113)

  },
  onPress: async() => {

    setdeletecancel(true)
    await notifee.cancelNotification(notificationId)
    homeStore. deleteAlarmToPost(data.note_id) 
    _onClose() 

  }
})

}, [])

const AlarmMessage=(type:string,deleteR:boolean=false) =>{ const message=type=="1"?t("createPost.alarm"):t("createPost.alarm") const description=type=="1"?t("createPost.alarm_ok"):t("createPost.alarmnot") showMessage({ message:message,// t("createPost.addtodetailTitle"), description:description,//t("createPost.addtodetail"), type:type=="1"?"success": "warning", icon:type=="1"? "success":"default", autoHide:true, onPress: () => { hideMessage()

 },

// onLongPress:()=>{ } })} const onDateChange = (event, selectedDate) => { setShowDatePicker(Platform.OS === 'ios'); setShowDatePicker if (selectedDate) { setDate(selectedDate); setShowTimePicker(true); } }; const onTimeChange = (event, selectedTime) => { setShowTimePicker(Platform.OS === 'ios'); if (selectedTime) { setchange(true) setTime(selectedTime); } console.log("23232,burraa") getdata() }; const createNotification = async () => {

const finalDateTime = new Date(
  date.getFullYear(),
  date.getMonth(),
  date.getDate(),
  time.getHours(),
  time.getMinutes()
);
  console.log(23423,new Date())
  console.log(23423,finalDateTime)
const trigger :TimestampTrigger= {
  type: TriggerType.TIMESTAMP,
  timestamp: finalDateTime.getTime(),
  alarmManager:{
    allowWhileIdle:true,
  }
};
console.log(43434,finalDateTime.getTime(),new Date().getTime())

if((finalDateTime.getTime()-new Date().getTime())>1*1000){

console.log(313) const channelId = await notifee.createChannel({ id: 'default', name: 'Default Channel', importance: AndroidImportance.HIGH,

});

const notificationId =  await notifee.createTriggerNotification(
  {
    title: title?.length?title:t("createPost.alarm"),
    body: body?.length?body:t("createPost.event"),
    android: {
      channelId: channelId,//'default',
      importance: AndroidImportance.HIGH,
      pressAction: { id: 'default',launchActivity: 'default',  }

    },
  },
  trigger,
);
console.log(28989,notificationId)
const newAlarm={
  alarm_id:notificationId,
  alarm_date:finalDateTime.getTime(),
  title: title?.length?title:t("createPost.alarm"),
  body: body?.length?body:t("createPost.event"),
    }
homeStore.addAlarmToPost(data.note_id, newAlarm)
AlarmMessage("1")
_onClose()
}else{
  AlarmMessage("2")
}

};

const finalDateTimeR = new Date( date.getFullYear(), date.getMonth(), date.getDate(), time.getHours(), time.getMinutes() ); return ( <AppBottomSheet onClose={_onClose} index={0} snapPoints={[screenHeight - 150]} backgroundStyle={{ opacity: 0 }} handleIndicatorStyle={{ backgroundColor: Colors.white50 }} ref={ref}

<Box topLeftRadius={16} topRightRadius={16} fill backgroundColor={Colors.white}

     <View style={{flex:1,alignContent:"center",flexDirection:"column",alignItems:"center",paddingTop:22}}>
   <AlarmSvg color={Colors.black} size={44}/>
   {showDatePicker && (
    <DateTimePicker
      value={date}
      mode="date"
      minimumDate={new Date()}
      display="default"
      onChange={onDateChange}
    />
  )}
  {showTimePicker && (
    <DateTimePicker
      value={time}
      mode="time"
      minimumDate={new Date()} 
      is24Hour={true}
      display="default"
      onChange={onTimeChange}
    />
  )}

  {who&& deletecancel==false?
      <View style={{padding:22,alignContent:"center",flexDirection:"column",alignItems:"center"}}>

  {/* bu alana */}
  <View style={{marginBottom: 10, alignItems: 'center'}}>
  <View style={{marginBottom: 10, alignItems: 'center'}}>
<Text style={{fontSize: 16,paddingTop:23, fontWeight: 'bold',color:"orange"}}>{t("createPost.Alarm_Date") }</Text>
<Text style={{fontSize: 16,paddingTop:3, fontWeight: 'bold'}}> { new Date(data.alarm[0].alarm_date).toLocaleDateString()+ " " +  new Date(data.alarm[0].alarm_date).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit',hour12: false })}</Text>
</View>

<View style={{ alignItems: 'center'}}>

<Text style={{fontSize: 16,paddingTop:23,fontWeight: 'bold',color:"orange"}}> {t("createPost.title") }</Text>
<Text style={{fontSize: 16,paddingTop:3,fontWeight: 'bold'}}> {data.alarm[0].title}</Text>
</View>

<View style={{marginBottom: 10, alignItems: 'center'}}>

<Text style={{fontSize: 16,paddingTop:23,fontWeight: 'bold',color:"orange"}}>{t("createPost.Description") }</Text>
<Text style={{fontSize: 16,paddingTop:3,fontWeight: 'bold'}}>{data.alarm[0].body}</Text>

 <TouchableOpacity 
   style={[styles.sendBtn,{
    marginTop:43,
            backgroundColor:"red"}]} 
  // disabled={change?false:true}
  onPress={()=>cancelDelete(data.alarm[0].alarm_id)}  >
  <Text style={styles.met}>{t("createPost.delete_Create_Reminder")} </Text>
  </TouchableOpacity>

    </View>
   :who==false&& deletecancel==false?
   <View>

  <View style={{padding:22,alignContent:"center",flexDirection:"column",alignItems:"center"}}>

<Text style={{fontWeight:"bold",color:change?"green":"black"}}>{change ? t("createPost.date_select")+: ${date.toLocaleDateString()} ${time.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit',hour12: false })} :t("createPost.Date_Not_Selected") } {(finalDateTimeR.getTime()-new Date().getTime())<1*1000 && change && <Text style={{fontWeight:"500",color:"red"}}>{ t("createPost.alarmmesage") } } <View style={{alignContent:"center",flexDirection:"column",alignItems:"center"}}>

  <TouchableOpacity 
   style={[styles.sendBtn,{}]} 
  onPress={() => setShowDatePicker(true)}
  >
  <Text style={styles.met}>{t("createPost.date_select")} </Text>
  </TouchableOpacity>
  </View>

  <View style={{flex:1,alignContent:"center",flexDirection:"column",alignItems:"center",paddingTop:42}}>
{change && {t("createPost.title")} }
     <View style={[styles.inputs,{marginVertical:23}]}>
      {change && 
     <Text style={{position:"absolute",left:0,top:-22, backgroundColor:"white"}}>{t("createPost.Description")}</Text>
      }
        <TextInput 
          placeholder={t("createPost.Description")}
          value={change?body:""}
          onChangeText={setBody}
          editable={change?true:false}
          maxLength={140} // Maksimum 50 karakter

        />
     </View>

 {
  <TouchableOpacity 
   style={[styles.sendBtn,{backgroundColor:change?Colors.primary:"gray"}]} 
  disabled={change?false:true}
  onPress={createNotification}  >
  <Text style={styles.met}>{t("createPost.Create_Reminder")} </Text>
  </TouchableOpacity>}
  </View>
  </View>:
         <View style={{padding:22,alignContent:"center",flexDirection:"column",alignItems:"center"}}>
        <Text>Silindi</Text>
        </View>
  }

     </View>
  </Box>
    {isIOS && <KeyboardSpacer />}
</AppBottomSheet>

); } )

export default memo( ReminderComponent)

github-actions[bot] commented 9 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.