Code example for PowerManager

Methods: isScreenOn

0
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        if (WIDGET_DATA_CHANGED_ACTION.equals(intent.getAction())
                || (SANS_JELLY_BEAN_MR1 && CLOCK_TICK_ACTION.equals(intent.getAction()))) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (pm.isScreenOn()) {
                onClockTick(context);
            } 
        } 
    } 
 
    protected abstract void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId);
 
    protected abstract void onClockTick(Context context);
 
    private PendingIntent createClockTickIntent(Context context) {
        Intent intent = new Intent(CLOCK_TICK_ACTION);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
        return pendingIntent;
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE