Proyectos de Subversion Android Microlearning - Inconcert

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 gabriel 1
package com.cesams.twogetskills.inconcert.service;
2
import android.content.Intent;
3
import android.util.Log;
4
 
5
import com.cesams.twogetskills.inconcert.Constants;
6
import com.cesams.twogetskills.inconcert.library.Functions;
7
import com.google.firebase.messaging.FirebaseMessagingService;
8
import com.google.firebase.messaging.RemoteMessage;
9
 
10
 
11
public class FcmMessagingService extends FirebaseMessagingService {
12
 
13
 
14
    private static final String TAG = "C2GS - FcmMessageServ";
15
 
16
 
17
    @Override
18
    public void onCreate() {
19
 
20
        super.onCreate();
21
        Log.e("BUG Token",  "FcmMessagingService - onCreate");
22
    }
23
 
24
    public void onMessageReceived(RemoteMessage remoteMessage) {
25
 
26
 
27
        Log.d("FcmMessagingService", "onMessageReceived");
28
 
29
        if (remoteMessage.getData().size() > 0) {
30
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
31
 
32
            if(remoteMessage.getData().containsKey("command")) {
33
                String command = remoteMessage.getData().get("command").trim();
34
 
35
                Intent intent = new Intent(Constants.BROADCAST_TYPE_COMMAND);
36
                intent.putExtra("command", command);
37
                getApplicationContext().sendBroadcast(intent);
38
            }
39
        }
40
        if (remoteMessage.getNotification() != null) {
41
            String title = remoteMessage.getNotification().getTitle();
42
            String body = remoteMessage.getNotification().getBody();
43
 
44
 
45
            String command = "", url="";
46
            int new_capsules = 0;
47
            if (remoteMessage.getData().size() > 0) {
48
                Log.d(TAG, "Message data payload: " + remoteMessage.getData());
49
 
50
                if(remoteMessage.getData().containsKey("command")) {
51
                    command = remoteMessage.getData().get("command").trim();
52
                }
53
 
54
                if(remoteMessage.getData().containsKey("new_capsules")) {
55
                   new_capsules = Functions.Numero2Int(remoteMessage.getData().get("new_capsules"));
56
                }
57
 
58
                if(remoteMessage.getData().containsKey("url")) {
59
                    url = remoteMessage.getData().get("url");
60
                }
61
            }
62
 
63
            Log.d(TAG, "title = " + title);
64
            Log.d(TAG, "body = " + body);
65
            Log.d(TAG, "command = " + command);
66
            Log.d(TAG, "new_capsules = " + new_capsules);
67
 
68
            Intent intent = new Intent(Constants.BROADCAST_TYPE_NOTIFICATION);
69
            intent.putExtra("title", title);
70
            intent.putExtra("body", body);
71
            intent.putExtra("command", command);
72
            intent.putExtra("new_capsules", new_capsules);
73
            intent.putExtra("url",url);
74
 
75
 
76
 
77
 
78
 
79
            if(command.equals("content-refresh")){
80
                intent.putExtra("content_refresh",true);
81
            } else {
82
                intent.putExtra("content_refresh",false);
83
            }
84
 
85
            getApplicationContext().sendBroadcast(intent);
86
        }
87
    }
88
 
89
 
90
 
91
 
92
    public void onNewToken(String fcm_token)
93
    {
94
        Log.e("BUG Token", "Token 2 :  " + fcm_token);
95
 
96
        Intent intent = new Intent(Constants.BROADCAST_TYPE_TOKEN);
97
        intent.putExtra("token", Functions.trimNull(fcm_token));
98
        getApplicationContext().sendBroadcast(intent);
99
 
100
 
101
    }
102
 
103
}