Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 8 | Rev 27 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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