设备未从SNS aws收到Firebase云消息传递通知

时间:2017-07-20 06:24:37

标签: android firebase firebase-cloud-messaging amazon-sns

我遇到FireBase云消息传递问题,我从该设备获取令牌并通过Google Firebase通知控制台发送通知测试,并通知移动设备。 但是我没有收到AWS SNS的通知?请让我知道任何有用的进一步信息。感谢。

MyFirebaseMessagingService.java

 public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "FROM:" + remoteMessage.getFrom());

        //check msz contains data
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data: " + remoteMessage.getData());
        }

        //check msz contains notification

        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message body: " + remoteMessage.getNotification().getBody());
            sendNotification(remoteMessage.getNotification().getBody());
            Log.d(TAG, "From: " + remoteMessage.getData());

            Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());


        }
    }


    ////Display notification

  private void sendNotification(String body) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT);
        //set sound for notification

        Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notifiBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("NewProject")
                .setContentText(body)
                .setAutoCancel(true)
                .setSound(notificationSound)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0/*Id of notification*/, notifiBuilder.build());
    }
}


**manifest**

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".MyFirebaseInstanceIdService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>

        </service>
    </application>

MyFirebaseInstanceIdService.java

 private static final String TAG="MyFirebaseInstanceIdService";

    @Override
    public void onTokenRefresh() {
        //get updated token
        String refreshedtoken= FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG,"New Token:" + refreshedtoken);

0 个答案:

没有答案