-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathFirestackMessagingService.java
More file actions
72 lines (63 loc) · 2.88 KB
/
FirestackMessagingService.java
File metadata and controls
72 lines (63 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.fullstack.firestack;
import android.content.Intent;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.SendException;
public class FirestackMessagingService extends FirebaseMessagingService {
private static final String TAG = "FSMessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Remote message received");
// debug
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
if (remoteMessage.getNotification() != null) {
}
Intent i = new Intent(FirestackCloudMessaging.INTENT_NAME_NOTIFICATION);
i.putExtra("data", remoteMessage);
sendOrderedBroadcast(i, null);
}
@Override
public void onMessageSent(String msgId) {
// Called when an upstream message has been successfully sent to the GCM connection server.
Log.d(TAG, "upstream message has been successfully sent");
Intent i = new Intent(FirestackCloudMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
sendOrderedBroadcast(i, null);
}
@Override
public void onSendError(String msgId, Exception exception) {
// Called when there was an error sending an upstream message.
Log.d(TAG, "error sending an upstream message");
Intent i = new Intent(FirestackCloudMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
i.putExtra("hasError", true);
SendException sendException = (SendException) exception;
i.putExtra("errorCode", sendException.getErrorCode());
switch(sendException.getErrorCode()){
case SendException.ERROR_INVALID_PARAMETERS:
i.putExtra("errorMessage", "Message was sent with invalid parameters.");
break;
case SendException.ERROR_SIZE:
i.putExtra("errorMessage", "Message exceeded the maximum payload size.");
break;
case SendException.ERROR_TOO_MANY_MESSAGES:
i.putExtra("errorMessage", "App has too many pending messages so this one was dropped.");
break;
case SendException.ERROR_TTL_EXCEEDED:
i.putExtra("errorMessage", "Message time to live (TTL) was exceeded before the message could be sent.");
break;
case SendException.ERROR_UNKNOWN:
default:
i.putExtra("errorMessage", "Unknown error.");
break;
}
sendOrderedBroadcast(i, null);
}
}