-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoIPMessagingService.java
More file actions
151 lines (129 loc) · 6.02 KB
/
VoIPMessagingService.java
File metadata and controls
151 lines (129 loc) · 6.02 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package io.CareAR.connect;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
//import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.MessagingUnityPlayerActivity;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
public class VoIPMessagingService extends FirebaseMessagingService {
private static String TITLE_KEY = "title";
private static String MESSAGE_KEY = "body";
public static String SESSION_ID_KEY = "sessionRoomID";
public static String CALLER_KEY = "displayName";
private static final String NOTIFICATION_ID_KEY = "NOTIFICATION_ID";
private static final String VOICE_CHANNEL = "default";
public class CallInvite {
public String title;
public String roomID;
public String callerName;
public String message;
public CallInvite(Map<String, String> body) {
message = body.get(MESSAGE_KEY);
roomID = body.get(SESSION_ID_KEY);
callerName = body.get(CALLER_KEY);
title = body.get(TITLE_KEY);
}
}
private NotificationManager notificationManager;
@Override
public void onCreate() {
super.onCreate();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages
// are handled
// here in onMessageReceived whether the app is in the foreground or background. Data
// messages are the type
// traditionally used with GCM. Notification messages are only received here in
// onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated
// notification is displayed.
// When the user taps on the notification they are returned to the app. Messages
// containing both notification
// and data payloads are treated as notification messages. The Firebase console always
// sends notification
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
// [END_EXCLUDE]
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d("VoIPMessagingService", "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d("VoIPMessagingService", "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d("VoIPMessagingService", "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Map<String, String> data = remoteMessage.getData();
CallInvite invite = new CallInvite(data);
Intent callIntent = new Intent(this, CallActivity.class);
callIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.putExtra(SESSION_ID_KEY, invite.roomID);
callIntent.putExtra(CALLER_KEY, invite.callerName);
startActivity(callIntent);
//showBasicNotification(invite);
}
// [END receive_message]
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("FCM", "Token: " + s);
}
/**
* Create and show a simple notification containing the received FCM message.
*
* @param invite FCM message body received.
*/
private void showBasicNotification(CallInvite invite) {
// Intent intent = new Intent(this, MessagingUnityPlayerActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
// PendingIntent.FLAG_ONE_SHOT);
//
// String channelId = getString(R.string.fcm_fallback_notification_channel_label);
// Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// NotificationCompat.Builder notificationBuilder =
// new NotificationCompat.Builder(this, channelId)
// .setSmallIcon(R.mipmap.app_icon)
// .setContentTitle(invite.title)
// .setContentText(invite.message)
// .setAutoCancel(true)
// .setSound(defaultSoundUri)
// .setContentIntent(pendingIntent);
//
// NotificationManager notificationManager =
// (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//
// // Since android Oreo notification channel is needed.
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// NotificationChannel channel = new NotificationChannel(channelId,
// "Channel human readable title",
// NotificationManager.IMPORTANCE_DEFAULT);
// notificationManager.createNotificationChannel(channel);
// }
//
// notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}