/documentation/RockLockTutorial/RockLock_05/src/com/marvin/rocklock/ScreenOnHandlerService.java
Java | 70 lines | 35 code | 13 blank | 22 comment | 1 complexity | 86f9daaede3facb3d050b4e561e80b4b MD5 | raw file
1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.marvin.rocklock; 18 19import android.app.Service; 20import android.content.BroadcastReceiver; 21import android.content.Context; 22import android.content.Intent; 23import android.content.IntentFilter; 24import android.os.IBinder; 25import android.util.Log; 26 27/** 28 * Service that registers a receiver to catch the screen on intent and launches 29 * the main RockLockActivity. 30 * 31 * @author clchen@google.com (Charles L. Chen) 32 */ 33public class ScreenOnHandlerService extends Service { 34 private BroadcastReceiver screenwakeup = new BroadcastReceiver() { 35 36 public static final String TAG = "screen wakeup"; 37 38 public static final String Screen = "android.intent.action.SCREEN_ON"; 39 40 @Override 41 public void onReceive(Context context, Intent intent) { 42 if (!intent.getAction().equals(Screen)) { 43 return; 44 } 45 46 Log.e(TAG, Screen); 47 48 Intent i = new Intent(context, RockLockActivity.class); 49 i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 50 context.startActivity(i); 51 } 52 }; 53 54 @Override 55 public IBinder onBind(Intent arg0) { 56 // Do nothing 57 return null; 58 } 59 60 @Override 61 public void onCreate() { 62 super.onCreate(); 63 64 this.startForeground(0, null); 65 66 IntentFilter onfilter = new IntentFilter(Intent.ACTION_SCREEN_ON); 67 this.registerReceiver(screenwakeup, onfilter); 68 } 69 70}