forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushReceiver.java
More file actions
103 lines (86 loc) · 3.27 KB
/
Copy pathPushReceiver.java
File metadata and controls
103 lines (86 loc) · 3.27 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
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
package com.runrev.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class PushReceiver extends BroadcastReceiver
{
public static final String TAG = "revandroid.PushReceiver";
public void onReceive(Context context, Intent intent)
{
Log.i(TAG, "received action:" + intent.getAction());
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION"))
{
handleRegistration(context, intent);
}
else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))
{
handleMessage(context, intent);
}
else
{
Log.i(TAG, "unhandled intent: " + intent);
}
}
private void handleRegistration(Context context, Intent intent)
{
String t_error = intent.getStringExtra("error");
String t_unregistered = intent.getStringExtra("unregistered");
String t_registration_id = intent.getStringExtra("registration_id");
if (t_error != null)
{
// error
Log.i(TAG, "registration error: " + t_error);
NotificationModule.handleRemoteRegistrationError(context, t_error);
}
else if (t_unregistered != null)
{
// unregistered
NotificationModule.handleRemoteUnregistration(context);
}
else if (t_registration_id != null)
{
// registered!
NotificationModule.handleRemoteRegistration(context, t_registration_id);
}
}
private void handleMessage(Context context, Intent intent)
{
String t_body = intent.getStringExtra("body");
String t_title = intent.getStringExtra("title");
String t_user_info = intent.getStringExtra("payload");
if (t_body == null)
t_body = "Notification received";
if (t_title == null)
t_title = Utils.getLabel(context);
if (t_user_info == null)
t_user_info = "";
boolean t_play_sound = false;
int t_badge_value = 0;
String t_extra = intent.getStringExtra("play_sound");
if (t_extra != null)
t_play_sound = Boolean.valueOf(t_extra);
try
{
t_extra = intent.getStringExtra("badge_value");
if (t_extra != null)
t_badge_value = Integer.valueOf(t_extra);
}
catch (NumberFormatException e)
{
t_badge_value = 0;
}
NotificationModule.handleRemoteMessage(context, t_body, t_title, t_user_info, t_play_sound, t_badge_value);
}
}