/**
* Copyright (C) 2015 Monitordroid Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Tyler Butler
**/
package com.monitordroid.app;
import static com.monitordroid.app.CommonUtilities.SENDER_ID;
import static com.monitordroid.app.CommonUtilities.displayMessage;
import android.content.Context;
import android.content.Intent;
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
super(SENDER_ID);
}
/**
* Method called on device registered
**/
@Override
protected void onRegistered(Context context, String registrationId) {
ServerUtilities.register(context, MainActivity.name,
MainActivity.email, registrationId);
}
/**
* Method called on device unregistred
* */
@Override
protected void onUnregistered(Context context, String registrationId) {
displayMessage(context, getString(R.string.gcm_unregistered));
ServerUtilities.unregister(context, registrationId);
}
/**
* Method called on receiving a new GCM message
*
* The GCM Message is extracted from an intent, then an instance of the
* MessageAction class is created and the message is forwarded there to get
* parsed.
**/
@Override
protected void onMessage(Context context, Intent intent) {
String message = intent.getExtras().getString("price");
if (message != null) {
// Feed the message into MessageAction for parsing
MessageAction ma = new MessageAction();
ma.actionParser(context, message);
}
}
/**
* Method called on receiving a deleted message
* */
@Override
protected void onDeletedMessages(Context context, int total) {
}
/**
* Method called on Error
* */
@Override
public void onError(Context context, String errorId) {
}
@Override
protected boolean onRecoverableError(Context context, String errorId) {
return super.onRecoverableError(context, errorId);
}
}