Notifications AWS SNS with android

37 Views Asked by At

i want to ask, right now i'm using react-native-notification and my problem which are i already publish message at AWS SNS and it is working fine with IOS but it not working for android. i received same log at IOS and Android. The notification at IOS can be seen but for android, it does not show anything. does i need to add to integrate with firebase? i also explore the Notifee but i dont know whether it is can integrate with AWS SNS.

here my code Android manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher"
      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>
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="myapp" />
          </intent-filter>
      </activity>

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/green" />
    </application>
</manifest>

here the code for notification

import { Notifications } from 'react-native-notifications';

const AwsNotification = async () => {
  //ios
  //register the device with the push service
  Notifications.registerRemoteNotifications();
  //setup the onRegistration listener (lambda for clarity)
  Notifications.events().registerRemoteNotificationsRegistered(token => {
    console.log('Notification tokens:', token.deviceToken);
  });
  Notifications.events().registerNotificationReceivedForeground(function (
    notification,
    completion,
  ) {
    console.log('Notification Received - Foreground', notification.payload);
    // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
    completion({ alert: true, sound: true, badge: false });
  });
  Notifications.events().registerNotificationOpened(function (
    notification,
    completion,
    action,
  ) {
    console.log('Notification opened by device user', notification.payload);
    console.log(
      `Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`,
    );
    completion({ alert: true, sound: true, badge: false });
  });
  Notifications.events().registerNotificationReceivedBackground(function (
    notification,
    completion,
  ) {
    console.log('Notification Received - Background', notification.payload);
    // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
    completion({ alert: true, sound: true, badge: false });
  });
};

export default AwsNotification;

here my main code

function App() {
  useEffect(() => {
    if (Platform.OS === 'android') {
      SplashScreen.hide();
      try {
        PermissionsAndroid.check('android.permission.POST_NOTIFICATIONS')
          .then(response => {
            if (!response) {
              PermissionsAndroid.request(
                'android.permission.POST_NOTIFICATIONS',
                {
                  title: 'Notification',
                  message:
                    'App needs access to your notification ' +
                    'so you can get Updates',
                  buttonNeutral: 'Ask Me Later',
                  buttonNegative: 'Cancel',
                  buttonPositive: 'OK',
                },
              );
            }
          })
          .catch(err => {
            console.log('Notification Error=====>', err);
          });
      } catch (err) {
        console.log(err);
      }
    }
    AwsNotification();
  }, []);

im expecting someone could tell me the requirement to make the android can receive the notification and if there any code was wrong, let me know.

0

There are 0 best solutions below