Proyectos de Subversion Android Microlearning

Rev

| Ultima modificación | Ver Log |

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