Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.content.Context;

import android.os.PowerManager;

import android.view.WindowManager;

public class Main {
    /**
     * Show the activity over the lockscreen and wake up the device. If you
     * launched the app manually both of these conditions are already true. If
     * you deployed from the IDE, however, this will save you from hundreds of
     * power button presses and pattern swiping per day!
     */
    public static void riseAndShine(Activity activity) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

        PowerManager power = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock lock = power.newWakeLock(
                PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
                "wakeup!");

        lock.acquire();
        lock.release();
    }
}