Java tutorial
//package com.java2s; import android.annotation.TargetApi; import android.app.Service; import android.content.Context; import android.os.Build; import android.os.PowerManager; public class Main { @TargetApi(Build.VERSION_CODES.M) public static boolean isDeviceIdleMode(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return false; } PowerManager pm = (PowerManager) context.getSystemService(Service.POWER_SERVICE); return pm.isDeviceIdleMode(); } }