1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.smssample.service; 18 19 import android.app.IntentService; 20 import android.content.Intent; 21 22 import com.example.android.smssample.receiver.MessagingReceiver; 23 24 /** 25 * This service is triggered internally only and is used to process incoming SMS and MMS messages 26 * that the {@link com.example.android.smssample.receiver.MessagingReceiver} passes over. It's 27 * preferable to handle these in a service in case there is significant work to do which may exceed 28 * the time allowed in a receiver. 29 */ 30 public class MessagingService extends IntentService { 31 private static final String TAG = "MessagingService"; 32 33 // These actions are for this app only and are used by MessagingReceiver to start this service 34 public static final String ACTION_MY_RECEIVE_SMS = "com.example.android.smssample.RECEIVE_SMS"; 35 public static final String ACTION_MY_RECEIVE_MMS = "com.example.android.smssample.RECEIVE_MMS"; 36 37 public MessagingService() { 38 super(TAG); 39 } 40 41 @Override 42 protected void onHandleIntent(Intent intent) { 43 if (intent != null) { 44 String intentAction = intent.getAction(); 45 if (ACTION_MY_RECEIVE_SMS.equals(intentAction)) { 46 // TODO: Handle incoming SMS 47 48 // Ensure wakelock is released that was created by the WakefulBroadcastReceiver 49 MessagingReceiver.completeWakefulIntent(intent); 50 } else if (ACTION_MY_RECEIVE_MMS.equals(intentAction)) { 51 // TODO: Handle incoming MMS 52 53 // Ensure wakelock is released that was created by the WakefulBroadcastReceiver 54 MessagingReceiver.completeWakefulIntent(intent); 55 } 56 } 57 } 58 } 59