/MusicLockTutorial/src/com/marvin/rocklock/ScreenOnHandlerService.java

http://eyes-free.googlecode.com/ · 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. package com.marvin.rocklock;
  17. import android.app.Service;
  18. import android.content.BroadcastReceiver;
  19. import android.content.Context;
  20. import android.content.Intent;
  21. import android.content.IntentFilter;
  22. import android.os.IBinder;
  23. import android.util.Log;
  24. /**
  25. * Service that registers a receiver to catch the screen on intent and launches
  26. * the main RockLockActivity.
  27. *
  28. * @author clchen@google.com (Charles L. Chen)
  29. */
  30. public class ScreenOnHandlerService extends Service {
  31. private BroadcastReceiver screenwakeup = new BroadcastReceiver() {
  32. public static final String TAG = "screen wakeup";
  33. public static final String Screen = "android.intent.action.SCREEN_ON";
  34. @Override
  35. public void onReceive(Context context, Intent intent) {
  36. if (!intent.getAction().equals(Screen)) {
  37. return;
  38. }
  39. Log.e(TAG, Screen);
  40. Intent i = new Intent(context, RockLockActivity.class);
  41. i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  42. context.startActivity(i);
  43. }
  44. };
  45. @Override
  46. public IBinder onBind(Intent arg0) {
  47. // Do nothing
  48. return null;
  49. }
  50. @Override
  51. public void onCreate() {
  52. super.onCreate();
  53. this.startForeground(0, null);
  54. IntentFilter onfilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
  55. this.registerReceiver(screenwakeup, onfilter);
  56. }
  57. }