You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, the app wouldn't even build after installing this package.
I'm using gradle 7 and this package uses deprecated maven dependencies.
To fix that I did some changes to the build.gradle that you can see in my comment here #175 ,but that's not the issue.
My problem is that when I create new alarms they never actually fire. When I use the scheduleAlarm fucntion I get an id back, and that id exists if I check getScheduledAlarms(), but when the time comes it just never fires.
I've disabled 'do not disturb', maxed my volume, still noting.
my code:
App.js
import ReactNativeAN from 'react-native-alarm-notification';
import { NativeEventEmitter, NativeModules } from 'react-native';
const { RNAlarmNotification } = NativeModules;
const RNAlarmEmitter = new NativeEventEmitter(RNAlarmNotification);
const dismissSubscription = RNAlarmEmitter.addListener(
'OnNotificationDismissed', (data) => console.log(JSON.parse(e))
);
const openedSubscription = RNAlarmEmitter.addListener(
'OnNotificationOpened', (data) => console.log(JSON.parse(e))
);
...
const launchAlarm = async () =>{
const fireDate = ReactNativeAN.parseDate(new Date(Date.now() + 5000)); // set the fire date for 1 second from now
const alarmNotifData = {
title: 'My Notification Title',
message: 'My Notification Message',
channel: '0',
small_icon: 'ic_launcher',
autoCancel: true,
bypassDnd: true,
loopSound: true,
volume:0.5,
// You can add any additional data that is important for the notification
// It will be added to the PendingIntent along with the rest of the bundle.
// e.g.
data: { foo: 'bar' },
};
const alarms = await ReactNativeAN.getScheduledAlarms();
console.log(alarms);
for (let i = 0; i < alarms.length; i++){
await ReactNativeAN.deleteAlarm(alarms[i]?.id);
}
//Schedule Future Alarm
try {
const alarm = await ReactNativeAN.scheduleAlarm({ ...alarmNotifData, fire_date: fireDate });
console.log(alarm); // { id: 1 }
} catch (e){
console.log('failed to create alarm- ',e);
}
}
class App extends Component {
...
render() {
return (
...
<Button
onPress={() => {
console.log('test');
launchAlarm();
}}
title="TEST BUTTON"
color="#DAD8D6"
accessibilityLabel="TEST BUTTON"
/>
...
);
}
}
MainActivity.java
...
import android.content.Intent;
import android.os.Bundle;
import com.emekalites.react.alarm.notification.BundleJSONConverter;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import org.json.JSONObject;
...
public class MainActivity extends ReactActivity {
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
try {
Bundle bundle = intent.getExtras();
if (bundle != null) {
JSONObject data = BundleJSONConverter.convertToJSON(bundle);
getReactInstanceManager().getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("OnNotificationOpened", data.toString());
}
} catch (Exception e) {
System.err.println("Exception when handling notification opened. " + e);
}
}
...
}
Would be glad for some help
The text was updated successfully, but these errors were encountered:
First of all, the app wouldn't even build after installing this package.
I'm using gradle 7 and this package uses deprecated maven dependencies.
To fix that I did some changes to the
build.gradle
that you can see in my comment here #175 ,but that's not the issue.My problem is that when I create new alarms they never actually fire. When I use the
scheduleAlarm
fucntion I get an id back, and that id exists if I checkgetScheduledAlarms()
, but when the time comes it just never fires.I've disabled 'do not disturb', maxed my volume, still noting.
my code:
App.js
MainActivity.java
Would be glad for some help
The text was updated successfully, but these errors were encountered: