react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

Why LargeIcon not display on android in background and closed app state?

Open ArchanaSharma95 opened this issue 4 years ago • 9 comments

I am not getting large icon if receiving notification in background or closed app state.

screenshot-2021 05 13-14_08_56

Here Top notification I am getting when app in foreground and second one when app is background. Please suggest how to show large icon in background and closed app state too.

This is a configuration I have inside project::

PushNotification.configure({
			// (required) Called when a remote or local notification is opened or received
			onNotification: this.clickOnOpenAppNotification,
			// IOS ONLY (optional): default: all - Permissions to register.
			permissions: { alert: true, badge: true, sound: true },
			// Should the initial notification be popped automatically
  			// default: true
			popInitialNotification: true,
			/**
			* (optional) default: true
			* - Specified if permissions (ios) and token (android and ios) will requested or not,
			* - if not, you must call PushNotificationsHandler.requestPermissions() later
			* - if you are not using remote notification or do not have Firebase installed, use this:
			*     requestPermissions: Platform.OS === 'ios'
			*/
			requestPermissions: true,
			largeIcon: 'ic_launcher',
			smallIcon: '@mipmap/notification_state',
		});

ArchanaSharma95 avatar May 13 '21 08:05 ArchanaSharma95

Hi @ArchanaSharma95 PushNotification.configure doesn't accept largeIcon or smallIcon, please recheck the Readme. Regards

Dallas62 avatar May 13 '21 08:05 Dallas62

@Dallas62 , thanks, can you suggest me how can I set these icons, as I am using onNotification trigger and it is automatically display my notification. Please suggest how can I set these icons.

ArchanaSharma95 avatar May 13 '21 08:05 ArchanaSharma95

https://github.com/zo0r/react-native-push-notification#local-notifications

Dallas62 avatar May 13 '21 08:05 Dallas62

@Dallas62 , I have used this inside onNotification handler function like this::

clickOnOpenAppNotification(notification) {
		console.log("noti", notification)
		PushNotification.localNotification({
			title: notification && notification.notification && notification.notification.title || '',
			message: notification && notification.notification && notification.notification.body || '',
			userInfo: notification.data,
			playSound: true,
			soundName: 'default',
			largeIcon: "ic_launcher",
			smallIcon: "@mipmap/notification_state",
		});
}

Still I am having same issue.

ArchanaSharma95 avatar May 13 '21 09:05 ArchanaSharma95

https://github.com/zo0r/react-native-push-notification/issues/1728#issuecomment-719434987

Dallas62 avatar May 13 '21 09:05 Dallas62

@Dallas62 I have checked my manifest file everything is set correctly. Also icons are added inside res folder.

 <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="false"/>
		 <!-- Change the resource name to your App's accent color - or any other color you want -->
		 <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white"/>
		 <meta-data  android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/notification_state" />

And now inside onMessage handler I am setting local notification like this. When I am getting remote notification then this returns a notification value and here I have added localNotification config like this:

this.notificationListener = messaging().onMessage(notification => {
	console.log("onMessage", notification)
	if (notification) {
		if (isIOS) {
			PushNotification.localNotification({
				title: notification && notification.notification && notification.notification.title || '',
				message: notification && notification.notification && notification.notification.body || '',
				userInfo: notification.data,
			});
		}
		else {
			PushNotification.localNotification({
				channelId: "my-channel",
				title: notification && notification.notification && notification.notification.title || '',
				message: notification && notification.notification && notification.notification.body || '',
				userInfo: notification.data,
				showWhen: true,
				// when: null,
				playSound: true,
				soundName: 'default',
				largeIcon: "@mipmap/ic_launcher",
				smallIcon: "@mipmap/notification_state",
			});
		}
	}
});

I am still not able to show large icon in background and closed app state. Please help I have already invested a day to add this icon.

ArchanaSharma95 avatar May 13 '21 10:05 ArchanaSharma95

@ArchanaSharma95 you should set name of icon = ic_notification

toanpv-2417 avatar May 25 '21 13:05 toanpv-2417

Hi, did you get your notification issue resolved?

ibtisamarif831 avatar Jun 09 '21 14:06 ibtisamarif831

Hi @ArchanaSharma95 did you find a work around for this?

Awesomer9561 avatar Sep 01 '22 19:09 Awesomer9561