when i set the alarm its working when app is open when i schedule the alarm and close the app its not working. I try on physical devices Android 11 but its not working.
Android Mainfiest code
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.emekalites.react.alarm.notification.ANService" android:enabled="true"/>
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="ACTION_DISMISS" />
<action android:name="ACTION_SNOOZE" />
</intent-filter>
</receiver>
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmDismissReceiver"
android:enabled="true"
android:exported="true" />
<receiver
android:name="com.emekalites.react.alarm.notification.AlarmBootReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
Schedule alarm
const alarmNotifData = {
title: 'Alarm Ringing', // Required
message: this.state.name, // Required
channel: 'alarm-channel', // Required. Same id as specified in MainApplication's onCreate method
ticker: 'My Notification Ticker',
auto_cancel: true, // default: true
vibrate: true,
vibration: 100, // default: 100, no vibration if vibrate: false
small_icon: 'ic_launcher', // Required
large_icon: 'ic_launcher',
play_sound: true,
sound_name: null, // Plays custom notification ringtone if sound_name: null
color: 'red',
schedule_once: true, // Works with ReactNativeAN.scheduleAlarm so alarm fires once
// tag: 'some_tag',
};
var alarm_id;
if (!isother) {
try {
alarm_id = await ReactNativeAN.scheduleAlarm({ ...alarmNotifData, fire_date: fireDate });
} catch (error) {
alert(error)
}
when i set the alarm its working when app is open when i schedule the alarm and close the app its not working
package.js
"#react-native-firebase/database": "^14.2.2",
"#react-native-firebase/messaging": "^14.2.2",
"#react-navigation/native": "^6.0.6",
"#react-navigation/stack": "^6.0.11",
"install": "^0.13.0",
"npm": "^8.3.0",
"react": "17.0.2",
"react-native": "0.66.4",
"react-native-alarm-notification": "^1.8.0",
I was read when you want show if app closed , you have to call that in background app refresh in android , you have to set push notification and this show even app closed , for android you can use firebase push notification and for ios basically use Apns or firebase too. for more info see this
Related
The dependencies used in the project are
"dependencies": {
"agora-react-native-rtm": "^1.5.0",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-agora": "^3.7.0"
},
Error log is
Note: Recompile with -Xlint:deprecation for details.
D:\Desktop\Codes\AgoraDemo\agorademo\android\app\src\main\AndroidManifest.xml
Error:
android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to
specify an explicit value for android:exported when the
corresponding component has an intent filter defined. See
https://developer.android.com/guide/topics/manifest/activity-element#exported
for details.
Here is the manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
BTW: Project works fine if all the agora related dependencies is removed
Solution:
For SDK 31 there is some issue with the "react-native-agora": "^3.7.0" version which will be fixed in a new one, meanwhile you can proceed with the workaround
https://github.com/AgoraIO-Community/react-native-agora/issues/496#issuecomment-1126508840
I have implemented react-native-push-notification to show localNotification from a RemoteMessage that I receive from FCM. I receive the notification but on tapping the notification, Linking.getInitialUrl() returns null. I also have react-native-bootsplash integrated for a splash screen. All the integration is as shown below.
AndroidManifest.xml
...
<activity android:name=".MainActivity" android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:exported="true" android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="#style/BootTheme" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this);
}
It seems that the data associated with the notification intent is not being sent to the Activity. So I am not able to find as to how I send the data.
I am developing a react-native app for Android. The app takes image sharing with this intent-filter on the main activity
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
I am able to get the initial sharing intent images by overriding getLaunchOptions(), but with this default launchMode="singleTask", I am not able to get new sharing intent when I have the existing instance of the app running.
So, how can I get the new sharing intent while have an instance of the app running?
PS: changing the launchMode to standard to standard kind of solved my problem, but that will create multiple instances of the app.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have the same problem. If the launchMode isn't in AndroidManifest.xml the situation is like standart.
I've found a solution for my case (receiving intents for .txt files)
In AndroidManifest.xml
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
...
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
In MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
onNewIntent(this.getIntent());
}
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// here are received intents
}
In such way I receive intents when app in background or it is not run at all and only ONE instance of the app.
I'm using React Native 0.61 and was having the exact same problem.
I've used the react-native-share-menu lib to make it work.
Alternatively, If you don't want to add a new lib to your project, it might be worth taking a look at how they did it for Android and modify your code accordingly:
https://github.com/meedan/react-native-share-menu/tree/master/android/src/main
so I've been trying to do this app but for some reason, after I can't seem to be able to detect notification from the firebase consol when the app is closed (not in the background or frontground those work fine).
so here are some of the relevant files.
componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
// Process your notification as required
notification.android.setChannelId('test-channel')
console.log("I'm called haha", notification);
firebase.notifications().displayNotification(notification)
});
this.messageListener = firebase.messaging().onMessage((message) => {
bgMessaging(message)
})
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
}
android manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobalib">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
android:exported="true">
<intent-filter>
<action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
</intent-filter>
</receiver>
</service>
<service
android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:launchMode="singleTop"
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
index.js:
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
and finaly bgMesseging.js:
xport default (message: RemoteMessage) => {
// handle your message
const title = message.get
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('My notification title')
.setBody('My notification body')
.setData({
key1: 'value1',
key2: 'value2',
});
notification
.android.setChannelId('test-channel')
firebase.notifications().displayNotification(notification)
console.log(message);
return Promise.resolve();
}
the TL/dr is that depending on what brand your phone is the notification can only be detected.
so Android not that great when it comes to this part of notification but it is so customisable on other thing that i do like it
I have used react-native-firebase in my react native project[android platform] to show the app notification. With this library i am able to show the notification when the app is in the foreground/background/closed state.
According to the react native firebase documentation the onNotificationOpened should be triggered when the app is opened by the notification tap. However this is not happening in my case, the onNotificationOpened method is never called and getInitialNotification method always gets a null value.
I am also using react-native-splash-screen library to display the splashscreen.
Here's my code from App.js >> componentDidMount()
firebase.messaging().requestPermission()
.then(() => {
const myAppChannel = new firebase.notifications.Android.Channel('my-channel',
'my Channel', firebase.notifications.Android.Importance.Max)
.setDescription('my channel');
firebase.notifications().android.createChannel(myAppChannel);
this.messageListener = firebase.messaging().onMessage((message) => {
const {title, body} = message.data;
const notificationDisplay = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(title)
.setBody(body)
.setData({
key1: 'value1',
key2: 'value2',
}).setSubtitle('notification')
.setSound('default');
notificationDisplay
.android.setChannelId('my-channel')
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true).android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(notificationDisplay);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
//never gets called
console.log('onNotificationOpened was triggered on notification taped');
});
})
.catch(error => {
// User has rejected permissions
console.log("user rejected");
console.log(error);
});
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id" />
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:exported="true"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
UPDATE: Problem was caused by the react-native-splash-screen library, I was able to fix this after removing the react-native-splash-screen library from the android project. However i am still not sure how i can make this work when using the react-native-splash-screen.
Adding intent-filter to MainActivity and click-action to notification JSON did the trick for me.
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Notification JSON
{
"to":"ID",
"notification" : {
**"click_action" : ".MainActivity",**
"body": "Message Body",
"title" : "Call Status",
"sound": "default",
"badge":"5"
},
"data": {
"type": 1,
"body": "Message Body",
"title" : "Call Status"
}
}
My manifest.xml looks like this
<application
tools:replace="android:allowBackup"
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme"
android:launchMode="singleTop"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Hope this helps