Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

In this page you can find the example usage for android.os PowerManager newWakeLock.

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java

/**
 * Called when a local notification broad cast is received. Funnels the notification
 * into the app if open or into the notification bar if not
 * /* w w  w  .  j a  va2 s.c om*/
 * @author Steven Hendrie
 * 
 * @param The context.
 * @param The intent.
 */
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context in_context, Intent in_intent) {
    //evaluate whether or not the main engine activity is in the foreground
    boolean isAppInForeground = false;
    if (CSApplication.get() != null && CSApplication.get().isActive() == true) {
        isAppInForeground = true;
    }

    //if the main engine activity is in the foreground, simply pass the
    //notification into it. Otherwise display a notification.
    if (isAppInForeground == true) {
        final Intent intent = new Intent(in_intent.getAction());
        Bundle mapParams = in_intent.getExtras();
        Iterator<String> iter = mapParams.keySet().iterator();

        while (iter.hasNext()) {
            String strKey = iter.next();
            intent.putExtra(strKey, mapParams.get(strKey).toString());
        }

        LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication
                .get().getSystem(LocalNotificationNativeInterface.InterfaceID);
        if (localNotificationNI != null) {
            localNotificationNI.onNotificationReceived(intent);
        }
    } else {
        //aquire a wake lock
        if (s_wakeLock != null) {
            s_wakeLock.release();
        }

        PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE);
        s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock");
        s_wakeLock.acquire();

        //pull out the information from the intent
        Bundle params = in_intent.getExtras();
        CharSequence title = params.getString(k_paramNameTitle);
        CharSequence text = params.getString(k_paramNameBody);
        int intentId = params.getInt(LocalNotification.k_paramNameNotificationId);

        int paramSize = params.size();
        String[] keys = new String[paramSize];
        String[] values = new String[paramSize];
        Iterator<String> iter = params.keySet().iterator();
        int paramNumber = 0;
        while (iter.hasNext()) {
            keys[paramNumber] = iter.next();
            values[paramNumber] = params.get(keys[paramNumber]).toString();
            ++paramNumber;
        }

        Intent openAppIntent = new Intent(in_context, CSActivity.class);
        openAppIntent.setAction("android.intent.action.MAIN");
        openAppIntent.addCategory("android.intent.category.LAUNCHER");
        openAppIntent.putExtra(k_appOpenedFromNotification, true);
        openAppIntent.putExtra(k_arrayOfKeysName, keys);
        openAppIntent.putExtra(k_arrayOfValuesName, values);
        openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        Bitmap largeIconBitmap = null;
        int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context,
                ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large");

        //Use small icon if no large icon
        if (LargeIconID == 0) {
            LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context,
                    ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify");
        }

        if (LargeIconID > 0) {
            largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID);
        }

        Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title)
                .setContentText(text)
                .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context,
                        ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"))
                .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build();

        NotificationManager notificationManager = (NotificationManager) in_context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(intentId, notification);
        Toast.makeText(in_context, text, Toast.LENGTH_LONG).show();
    }
}

From source file:net.pmarks.chromadoze.NoiseService.java

@Override
public void onCreate() {
    // Set up a message handler in the main thread.
    mPercentHandler = new PercentHandler();
    AudioParams params = new AudioParams();
    mSampleShuffler = new SampleShuffler(params);
    mSampleGenerator = new SampleGenerator(this, params, mSampleShuffler);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ChromaDoze Wake Lock");
    mWakeLock.acquire();//from  www.  j  av a2  s.com

    startForeground(NOTIFY_ID, makeNotify());

    // Note: This leaks memory if I use "this" instead of "getApplicationContext()".
    mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), mSampleShuffler.getVolumeListener());
}

From source file:net.kayateia.lifestream.UploadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(LOG_TAG, "UploadService kicked");

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");

    // See CaptureService for comments on this wake lock arrangement.
    boolean needsRelease = true;
    try {//www. jav  a2  s .  c o m
        // If we don't release it within the timeout somehow, release it anyway.
        // This may interrupt a long backlog upload or something, but this
        // is really about as long as we can reasonably expect to take.
        Log.v(LOG_TAG, "Acquire wakelock");
        if (wl != null)
            wl.acquire(WAKELOCK_TIMEOUT);
        if (!Network.IsActive(this)) {
            Log.i(LOG_TAG, "No network active, giving up");
            return START_NOT_STICKY;
        }

        // Do the check in a thread.
        new AsyncTask<UploadService, Void, Void>() {
            @Override
            protected Void doInBackground(UploadService... svc) {
                svc[0].checkUploads();
                return null;
            }

            @Override
            protected void onPostExecute(Void foo) {
                Log.v(LOG_TAG, "Release wakelock by worker");
                if (wl != null && wl.isHeld())
                    wl.release();
            }
        }.execute(this);
        needsRelease = false;
    } finally {
        if (needsRelease) {
            Log.v(LOG_TAG, "Release wakelock by default");
            if (wl != null && wl.isHeld())
                wl.release();
        }
    }

    // There's no need to worry about this.. we'll get re-kicked by the alarm.
    return START_NOT_STICKY;
}

From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java

@SuppressWarnings("deprecation")
@Override// w  ww . j  ava2 s. c  o  m
public void onCreate() {
    created = true;

    settings = new RecSettings();
    settings.load(getApplicationContext(),
            PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));

    createNotification(NOTIFICATION_ID);

    if (settings.isSchedRecEnabled() && settings.getSchedRecTime() > System.currentTimeMillis() + 10000) {
        AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplicationContext(), ScheduleReceiver.class);
        PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);

        alarmMgr.set(AlarmManager.RTC_WAKEUP, settings.getSchedRecTime(), alarmIntent);

        stopSelf();
        return;
    }

    // Create new SurfaceView, set its size to 1x1, move
    // it to the top left corner and set this service as a callback
    WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    surfaceView = new SurfaceView(this);
    // deprecated setting, but required on Android versions prior to 3.0
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceView.getHolder().addCallback(this);

    LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    winMgr.addView(surfaceView, layoutParams);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire();
}

From source file:com.google.android.marvin.talkback.ProcessorVolumeStream.java

@SuppressWarnings("deprecation")
public ProcessorVolumeStream(TalkBackService service) {
    mContext = service;/* w  w  w  .  ja  v a 2 s .c o  m*/
    mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
    mCursorController = service.getCursorController();
    mFeedbackController = service.getFeedbackController();
    mLongPressHandler = new LongPressHandler(this);

    final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG);
}

From source file:com.android.camera.processing.ProcessingService.java

@Override
public void onCreate() {
    mProcessingServiceManager = ProcessingServiceManager.instance();
    mSessionManager = getServices().getCaptureSessionManager();

    // Keep CPU awake while allowing screen and keyboard to switch off.
    PowerManager powerManager = AndroidServices.instance().providePowerManager();
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG.toString());
    mWakeLock.acquire();//from   ww w  .j a  va  2  s .  c  om

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ACTION_PAUSE_PROCESSING_SERVICE);
    intentFilter.addAction(ACTION_RESUME_PROCESSING_SERVICE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mServiceController, intentFilter);
    mNotificationBuilder = createInProgressNotificationBuilder();
    mNotificationManager = AndroidServices.instance().provideNotificationManager();
}

From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java

/**
 * OnRecieve method that recieves calls form the AlertManager class and then applies some logic to fire notifications to the user.
 *
 * @param context//  w ww .  ja  v a  2  s . c o  m
 * @param intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onRecieve");
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MedMinder");
    //Acquire the lock
    wl.acquire();

    dose = null;
    dose = (Dose) intent.getSerializableExtra(AlertManager.ALARMSTRING);
    Log.d(TAG,
            " This dose is " + dose.getMedication().getMedName() + "  " + dose.getDoseTime().toString(dtfTime));

    if (dose == null) {
        Log.d(TAG, "Alert object Extra is null");
    }

    //get the parent med
    Medication med = dose.getMedication();
    int alertCount = 0;
    for (DateTime doseDueDT : med.getDoseMap1().keySet()) {
        DateTime doseTakenDT = med.getDoseMap1().get(doseDueDT);
        if (doseDueDT.isBefore(new DateTime().now())
                && doseDueDT.isAfter(new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0))
                && doseTakenDT.equals(new DateTime(0))) {
            alertCount++;
        }
    }

    if (alertCount == 0) {
        return;
    }

    SharedPreferences sharedPref = context.getSharedPreferences("AlertCounter", 0);
    int alertCountPref = sharedPref.getInt(med.getMedName(), 0);
    SharedPreferences.Editor editor = sharedPref.edit();

    DateTime now = new DateTime().now();
    int notifID = dose.getMedication().getDbID();
    Random rand = new Random();
    //int notifID = rand.nextInt();
    Log.d(TAG, dose.getMedication().getDbID() + "   " + dose.getDoseTime().getMillisOfDay());

    if (dose.getTakenTime().toString(dtfDate).equals(new DateTime(0).toString(dtfDate))) {
        //            if ((dose.getDoseTime().getMillis() + alertMissedWindowArray[dose.getMedication().getFreq() - 1] * 2) > new DateTime().getMillis());
        String alertString = "You have " + alertCount + " missed doses for " + med.getMedName();
        if (alertCount == 1) {
            alertString = "You have a missed dose for " + med.getMedName();
        }

        //check if the dose is due +/- 15mins and advise that a dose is due.
        long diffMillis = dose.getDoseTime().getMillis() - new DateTime().now().getMillis();
        Log.d(TAG, diffMillis + "   dose time = " + dose.getDoseTime().getMillis() + " now= "
                + new DateTime().now().getMillis());
        boolean doseDue = Math.abs(diffMillis) < 1800000;
        if (doseDue) {
            alertString = dose.getMedication().getDose() + " of " + dose.getMedication().getMedName()
                    + " is due now.";
        }

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.medminder_icon).setContentTitle("MedMinder").setContentText(alertString);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, MainActivity.class);

        // The stack builder object will contain an artificial back stack for the started Activity.
        // This ensures that navigating backward from the Activity leads out of your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(MainActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        // mId allows you to update the notification later on.
        mNotificationManager.notify(notifID, mBuilder.build());
        Log.d(TAG, " Notification sent " + notifID);
        //
        //
        //            editor.putInt(med.getMedName(), alertCount);
        //            editor.commit();

        //Release the lock
        wl.release();
    }
}

From source file:com.digutsoft.metronome.DMFSetTempo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.settempo, container, false);

    sbTempo = (SeekBar) rootView.findViewById(R.id.sbTempo);
    tvTempo = (TextView) rootView.findViewById(R.id.tvTempo);
    final CircledImageView btStart = (CircledImageView) rootView.findViewById(R.id.btStart);
    final CircledImageView btPlus = (CircledImageView) rootView.findViewById(R.id.btPlus);
    final CircledImageView btMinus = (CircledImageView) rootView.findViewById(R.id.btMinus);

    mContext = getActivity().getApplicationContext();

    final Context mContext = getActivity();
    sharedPreferences = mContext.getSharedPreferences("dMetronome", 0);
    int defaultTempo = sharedPreferences.getInt("tempo", 80);
    setTempo(defaultTempo);/*  w w  w .ja v  a 2s.c  om*/

    Intent viewIntent = new Intent(getActivity(), DMAMain.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(getActivity(), 0, viewIntent, 0);

    notificationBuilder = new NotificationCompat.Builder(getActivity()).setOngoing(true)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentIntent(viewPendingIntent);

    notificationManager = NotificationManagerCompat.from(getActivity());

    Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    metronome = new DMCMetronome(getActivity(), vibrator, rootView.findViewById(R.id.bilBackground));

    PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getString(R.string.app_name));

    sbTempo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setTempo(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    btStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mTempo == 0) {
                Toast.makeText(getActivity(), R.string.tempo_zero, Toast.LENGTH_LONG).show();
                return;
            }

            if (DMCMetronome.mRunning) {
                metronome.stopTick();

                sbTempo.setEnabled(true);
                tvTempo.setText(Integer.toString(mTempo));
                btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_start));
                btStart.setCircleColor(getResources().getColor(R.color.green));
                btPlus.setVisibility(View.VISIBLE);
                btMinus.setVisibility(View.VISIBLE);

                wakeLock.release();

                notificationManager.cancel(1);
            } else {
                metronome.startTick(mTempo);

                sbTempo.setEnabled(false);
                btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_stop));
                btStart.setCircleColor(getResources().getColor(R.color.red));
                btPlus.setVisibility(View.GONE);
                btMinus.setVisibility(View.GONE);

                wakeLock.acquire();

                notificationBuilder
                        .setContentText(String.format(getString(R.string.notification_running), mTempo));
                notificationManager.notify(1, notificationBuilder.build());

                sharedPreferences.edit().putInt("tempo", mTempo).apply();
            }
        }
    });

    btPlus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setTempo(mTempo + 1);
        }
    });

    btMinus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setTempo(mTempo - 1);
        }
    });

    return rootView;
}

From source file:org.android.gcm.client.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs = getSharedPreferences("gcmclient", Context.MODE_PRIVATE);
    pushpak = prefs.getString("push_pak", "");
    pushact = prefs.getString("push_act", "");
    final boolean pushon = prefs.getBoolean("push_on", true);
    final boolean pushnotif = prefs.getBoolean("push_notification", true);

    if (pushnotif) {
        final String notifact = prefs.getString("notification_act", "");
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        // The getMessageType() intent parameter must be the intent you received
        // in your BroadcastReceiver.
        String messageType = gcm.getMessageType(intent);

        // Send a notification.
        if (!extras.isEmpty()) { // has effect of unparcelling Bundle
            /*/* ww w .  j  av a 2s .c  om*/
             * Filter messages based on message type. Since it is likely that GCM will be
             * extended in the future with new message types, just ignore any message types you're
             * not interested in, or that you don't recognize.
             */
            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendNotification(getString(R.string.send_error) + ": " + extras.toString(), notifact);
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendNotification(getString(R.string.deleted) + ": " + extras.toString(), notifact);
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // Post notification of received message.
                sendNotification(
                        getString(R.string.received, extras.getString("name"), extras.getString("num")),
                        notifact);
                Log.i(TAG, "Received: " + extras.toString());
            }
        }
    }

    // End if push is not enabled.
    if (!pushon) {
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
        return;
    }

    final boolean fullwake = prefs.getBoolean("full_wake", false);
    final boolean endoff = prefs.getBoolean("end_off", true);

    // Manage the screen.
    PowerManager mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock mWakeLock = mPowerManager
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
    boolean misScreenOn = mPowerManager.isScreenOn();
    int mScreenTimeout = 0;
    if (!misScreenOn) {
        if (endoff) {
            // Change the screen timeout setting.
            mScreenTimeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT,
                    0);
            if (mScreenTimeout != 0) {
                Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 3000);
            }
        }
        // Full wake lock
        if (fullwake) {
            mWakeLock.acquire();
        }
    }

    // Start the activity.
    try {
        startActivity(getPushactIntent(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
        // Wait to register.
        Thread.sleep(REGISTER_DURATION);
    } catch (android.content.ActivityNotFoundException e) {
        RING_DURATION = 0;
        Log.i(TAG, "Activity not started");
    } catch (InterruptedException e) {
    }

    // Release the wake lock.
    if (!misScreenOn && fullwake) {
        mWakeLock.release();
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);

    // Restore the screen timeout setting.
    if (endoff && mScreenTimeout != 0) {
        try {
            Thread.sleep(RING_DURATION);
        } catch (InterruptedException e) {
        }
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, mScreenTimeout);
    }
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TouchWakelockTag");

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    if (!mWakeLock.isHeld()) {
        mWakeLock.acquire();//  w  w w  .  j av  a  2  s  .  co  m
    }

    // Get intent data.
    setRegisterEvent(getIntent());
    setContentView(R.layout.activity_wear_touch_profile);
    mGestureDetector = new GestureDetector(this, mSimpleOnGestureListener);

    // For service destruction suppression.
    Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);
}