Example usage for android.os PowerManager isInteractive

List of usage examples for android.os PowerManager isInteractive

Introduction

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

Prototype

public boolean isInteractive() 

Source Link

Document

Returns true if the device is in an interactive state.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static boolean isInteractive(PowerManager pm) {
    boolean result = false;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        result = pm.isInteractive();
    } else {//from   ww  w . j a va  2 s  .c o  m
        result = pm.isScreenOn();
    }

    return result;
}

From source file:Main.java

/**
 * @return Whether the screen of the device is interactive.
 *///www. j  a  va 2  s  . c  o  m
@SuppressWarnings("deprecation")
public static boolean isInteractive(Context context) {
    PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return manager.isInteractive();
    } else {
        return manager.isScreenOn();
    }
}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static boolean isScreenOn(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return powerManager.isInteractive();
    }/*from   ww w.  j  a  v  a  2  s.c  om*/
    return powerManager.isScreenOn();
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isInteractive(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH)
        return (pm != null && pm.isScreenOn());
    else/*from w  w w . ja  v a 2s .  co m*/
        return (pm != null && pm.isInteractive());
}

From source file:org.matrix.console.activity.HomeActivity.java

@SuppressLint("NewApi")
private boolean isScreenOn() {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return powerManager.isInteractive();
    } else {/*  w  ww  . ja  v a 2  s  .co m*/
        return powerManager.isScreenOn();
    }
}

From source file:rp.soi.dmsd.notextingwhilewalking.DetectedActivitiesIntentService.java

/**
 * Handles incoming intents.//from   www . j  a va 2s  .c  o  m
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mSensorManager.registerListener(this, mOrientation, SensorManager.SENSOR_DELAY_NORMAL);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(rp.soi.dmsd.notextingwhilewalking.Constants.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, rp.soi.dmsd.notextingwhilewalking.Constants.getActivityString(getApplicationContext(),
                da.getType()) + " " + da.getConfidence() + "%");
        // trigger a notification if the walking activity has a confidence of > 50%

        //float[] xyz = mSensorManager.getOrientation();

        if (da.getType() == DetectedActivity.WALKING && da.getConfidence() > 15) {

            // For API 20 and higher
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Log.i(TAG, "Android version is HIGHER than 20 ");
                if (powerManager.isInteractive()) {
                    Log.i(TAG, "Screen is ON");
                    if (isPhoneFacingUp) {
                        Log.i(TAG, "Phone is facing UP.");
                        createNotification(true);
                    } else {
                        Log.i(TAG, "Phone is facing DOWN.");
                    }
                } else {
                    Log.i(TAG, "Screen is OFF");
                }
            } else {
                Log.i(TAG, "Android version is LOWER than 20 ");
                if (powerManager.isScreenOn()) {
                    Log.i(TAG, "Screen is ON");
                    if (isPhoneFacingUp) {
                        Log.i(TAG, "Phone is facing UP.");
                        createNotification(true);
                    } else {
                        Log.i(TAG, "Phone is facing DOWN.");
                    }
                } else {
                    Log.i(TAG, "Screen is OFF");
                }
            }
        }

    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}

From source file:com.android.tv.MainActivity.java

@Override
protected void onStop() {
    if (DEBUG)//  ww  w.  j ava 2s.  c o m
        Log.d(TAG, "onStop()");
    if (mScreenOffIntentReceived) {
        mScreenOffIntentReceived = false;
    } else {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!powerManager.isInteractive()) {
            // We added to check isInteractive as well as SCREEN_OFF intent, because
            // calling timing of the intent SCREEN_OFF is not consistent. b/25953633.
            // If we verify that checking isInteractive is enough, we can remove the logic
            // for SCREEN_OFF intent.
            markCurrentChannelDuringScreenOff();
        }
    }
    mActivityStarted = false;
    stopAll(false);
    unregisterReceiver(mBroadcastReceiver);
    mTracker.sendMainStop(mMainDurationTimer.reset());
    super.onStop();
}