PushNotification.onRegister is called twice on android causing duplicate endpoints in Pinpoint segment. This bug causes duplicate push notifications sent to android devices.
Code:
import Amplify from 'aws-amplify';
import { PushNotification } from 'aws-amplify-react-native';
import aws_exports from '../aws-exports';
// PushNotification need to work with Analytics
Amplify.configure(aws_exports);
PushNotification.configure(aws_exports);
// get the notification data
PushNotification.onNotification((notification) => {
// Note that the notification object structure is different from Android and IOS
console.log('in app notification', notification);
if(Platform.OS === 'ios') {
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
});
// get the registration token
PushNotification.onRegister((token) => {
console.log('in app registration', token);
});
Console output:
{[DEBUG] 56:04.895 Notification - update endpoint in push notification: "d-BxWr2r6sU:APA91bHyoJ7bocoq4KeF3wyBIM8XQwMIGSTgt8鈥737-LwwpzEvSTDL6cdyuS1n9XOwhuLKatDv7gFblh2u-h9Ig"}
in app registration d-BxWr2r6sU:APA91bHyoJ7bocoq4KeF3wyBIM8XQwMIGSTgt8TZOy58gbCingQeDjue3EHton2krKhwY_HFpUsvgAQk8HodbJIkx5oGq9de42fLn3nPHV92YVWTBT737-LwwpzEvSTDL6cdyuS1n9XOwhuLKatDv7gFblh2u-h9Ig
{[DEBUG] 56:04.962 Notification - update endpoint in push notification: "d-BxWr2r6sU:APA91bHyoJ7bocoq4KeF3wyBIM8XQwMIGSTgt8鈥737-LwwpzEvSTDL6cdyuS1n9XOwhuLKatDv7gFblh2u-h9Ig"}[DEBUG] 56:04.962 Notification - update endpoint in push notification: "d-BxWr2r6sU:APA91bHyoJ7bocoq4KeF3wyBIM8XQwMIGSTgt8TZOy58gbCingQeDjue3EHton2krKhwY_HFpUsvgAQk8HodbJIkx5oGq9de42fLn3nPHV92YVWTBT737-LwwpzEvSTDL6cdyuS1n9XOwhuLKatDv7gFblh2u-h9Ig"__proto__: Object
in app registration d-BxWr2r6sU:APA91bHyoJ7bocoq4KeF3wyBIM8XQwMIGSTgt8TZOy58gbCingQeDjue3EHton2krKhwY_HFpUsvgAQk8HodbJIkx5oGq9de42fLn3nPHV92YVWTBT737-LwwpzEvSTDL6cdyuS1n9XOwhuLKatDv7gFblh2u-h9Ig
This issue should be fixed per this merge: #1428
I had to remove
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
from AndroidManifest.xml
@abhaykumar1415
worked for me
Most helpful comment
I had to remove
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
from AndroidManifest.xml