Make custom server work when polling
[fonbot.git] / src / ro / ieval / fonbot / GCMIntentService.java
CommitLineData
8dfb76c9
MG
1package ro.ieval.fonbot;
2
3import org.eclipse.jdt.annotation.Nullable;
4
5import android.content.Context;
6import android.content.Intent;
7import android.os.Handler;
8import android.os.Looper;
9
10import com.google.android.gcm.GCMBaseIntentService;
11
12/*
13 * Copyright © 2013 Marius Gavrilescu
14 *
15 * This file is part of FonBot.
16 *
17 * FonBot is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * FonBot is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31/**
32 * Service that responds to GCM events
33 *
34 * @author Marius Gavrilescu <marius@ieval.ro>
35 */
36public class GCMIntentService extends GCMBaseIntentService {
37 /** Handler instance */
38 private final Handler handler=new Handler(Looper.getMainLooper());
39
40 /**
41 * Constructs a GCMIntentService with the iEval sender id
42 */
43 public GCMIntentService() {
44 super(FonBotApplication.GCM_SENDER_ID);
45 }
46
47 @Override
48 protected void onError(@Nullable final Context context, @Nullable final String errID) {
49 //TODO error handling here
50 }
51
52 @Override
53 protected void onMessage(@Nullable final Context context, @Nullable final Intent intent) {
a97d31fb
MG
54 if(context==null)
55 return;
56
8dfb76c9
MG
57 handler.post(new Runnable(){
58 @Override
59 public void run() {
a97d31fb 60 new PollServerAsyncTask(context).execute();
8dfb76c9
MG
61 }
62 });
63 }
64
65 @Override
66 protected void onRegistered(@Nullable final Context context, @Nullable final String regID) {
67 FonBotApplication.instance.regID=regID;
68 }
69
70 @Override
71 protected void onUnregistered(@Nullable final Context context, @Nullable final String regID) {
72 //do nothing
73 }
74}
This page took 0.012558 seconds and 4 git commands to generate.