-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGcmMessageHandler.java
55 lines (42 loc) · 1.72 KB
/
GcmMessageHandler.java
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
package in.antaragni.ant;
import com.google.android.gms.gcm.GcmListenerService;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import in.antaragni.ant.datahandler.DatabaseAccess;
public class GcmMessageHandler extends GcmListenerService {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
private DatabaseAccess databaseAccess;
@Override
public void onMessageReceived(String from, Bundle data) {
String title = data.getString("title");
String time = data.getString("time");
String venue = data.getString("venue");
String event_name = data.getString("eventname");
String message = "" ;
message = message.concat(event_name);
databaseAccess = DatabaseAccess.getInstance(this);
databaseAccess.open();
if (!time.isEmpty()) {
databaseAccess.updateinfo(event_name, Integer.parseInt(time));
message = message.concat( " " + time);
}
if (!venue.isEmpty()) {
databaseAccess.updateinfo(event_name, venue);
message = message.concat( " " + venue);
}
createNotification(title, message);
databaseAccess.close();
}
// Creates notification based on title and body received
private void createNotification(String title, String body) {
Context context = getBaseContext();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title)
.setContentText(body);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
}