android.hardware.display.DisplayManager Java Examples
The following examples show how to use
android.hardware.display.DisplayManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DimScreenActivity.java From Taskbar with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tb_activity_hsl_config); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); TextView textView = findViewById(R.id.textView); textView.setText(R.string.tb_desktop_mode_is_active); DisplayManager manager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); manager.registerDisplayListener(listener, null); U.registerReceiver(this, unDimScreenReceiver, ACTION_UNDIM_SCREEN); U.registerReceiver(this, finishReceiver, ACTION_FINISH_DIM_SCREEN_ACTIVITY, ACTION_KILL_HOME_ACTIVITY); if(getSupportActionBar() == null) return; // Make action bar invisible getSupportActionBar().setElevation(0); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0)); setTitle(null); }
Example #2
Source File: WindowCaptureFragment.java From ViewCapture with Apache License 2.0 | 6 votes |
public Bitmap capture() { try { mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG, windowWidth, windowHeight, mScreenDensity, // DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,// mImageReader.getSurface(), null, null); Log.i(TAG, "screen capture completed"); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } return createBitmap(); } finally { release(); } }
Example #3
Source File: OverlayDisplayWindow.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public OverlayDisplayWindow(Context context, String name, int width, int height, int densityDpi, int gravity, boolean secure, Listener listener) { // Workaround device freeze (b/38372997) ThreadedRenderer.disableVsync(); mContext = context; mName = name; mGravity = gravity; mSecure = secure; mListener = listener; mDisplayManager = (DisplayManager)context.getSystemService( Context.DISPLAY_SERVICE); mWindowManager = (WindowManager)context.getSystemService( Context.WINDOW_SERVICE); mDefaultDisplay = mWindowManager.getDefaultDisplay(); updateDefaultDisplayInfo(); resize(width, height, densityDpi, false /* doLayout */); createWindow(); }
Example #4
Source File: ScreenCaptureService.java From pc-android-controller-android with Apache License 2.0 | 6 votes |
/** * 将录屏服务的内容显示到Image面板上. */ private void initVirtualDisplay() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { DisplayManager mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE); if (mDisplayManager == null) { L.e(" 获取 播放管理器失败 ... "); } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { L.d("当前安卓 版本 " + Build.VERSION.SDK_INT + " 进入到图片展示 "); mVirtualDisplay = mDisplayManager.createVirtualDisplay("Remote Droid", mScreenWidth, mScreenHeight, mScreenDensity, mImageReader.getSurface(), DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE); } } else { if (mMediaProjection == null) { L.e("mMediaProjection is null ..."); return; } else { mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror", mScreenWidth, mScreenHeight, mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mImageReader.getSurface(), null, null); } } }
Example #5
Source File: OffscreenDisplay.java From FirefoxReality with Mozilla Public License 2.0 | 6 votes |
public void onResume() { if (mVirtualDisplay == null) { DisplayManager manager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); Display defaultDisplay = manager.getDisplay(Display.DEFAULT_DISPLAY); int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; defaultDisplay.getMetrics(mDefaultMetrics); mVirtualDisplay = manager.createVirtualDisplay("OffscreenViews", mWidth, mHeight, mDefaultMetrics.densityDpi, mSurface, flags); } if (mPresentation == null) { mPresentation = new OffscreenPresentation(mContext, mVirtualDisplay.getDisplay()); mPresentation.show(); if (mContentView != null) { mPresentation.setContentView(mContentView); } } }
Example #6
Source File: MediaProjectionManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override // Binder call public int applyVirtualDisplayFlags(int flags) { if (mType == MediaProjectionManager.TYPE_SCREEN_CAPTURE) { flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION; return flags; } else if (mType == MediaProjectionManager.TYPE_MIRRORING) { flags &= ~(DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR); flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION; return flags; } else if (mType == MediaProjectionManager.TYPE_PRESENTATION) { flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; return flags; } else { throw new RuntimeException("Unknown MediaProjection type"); } }
Example #7
Source File: AndroidMessenger.java From actor-platform with GNU Affero General Public License v3.0 | 6 votes |
private boolean isScreenOn() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); boolean screenOn = false; for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { screenOn = true; } } return screenOn; } else { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); //noinspection deprecation return pm.isScreenOn(); } }
Example #8
Source File: HelperNotificationAndBadge.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
/** * Is the screen of the device on. * * @param context the context * @return true when (at least one) screen is on */ public boolean isScreenOn(Context context) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); boolean screenOn = false; for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { screenOn = true; } } return screenOn; } else { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); } }
Example #9
Source File: WatchFaceActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the display manager and register a listener (this activity). displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); // displayManager.registerDisplayListener(this, null); }
Example #10
Source File: HyperionScreenEncoder.java From hyperion-android-grabber with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void prepare() throws MediaCodec.CodecException { if (DEBUG) Log.d(TAG, "Preparing encoder"); mVirtualDisplay = mMediaProjection.createVirtualDisplay( TAG, getGrabberWidth(), getGrabberHeight(), mDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, null, mDisplayCallback, null); setImageReader(); }
Example #11
Source File: ScreenShotActivity.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void virtualDisplay() { mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror", getScreenWidth(), getScreenHeight(), Resources.getSystem().getDisplayMetrics().densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mImageReader.getSurface(),null, null); }
Example #12
Source File: MiracastWidgetProvider.java From miracast-widget with Apache License 2.0 | 5 votes |
public MiracastDisplayListener(int currentDisplay, RemoteViews widgetRemoteViews, DisplayManager displayManager, AppWidgetManager appWidgetManager, int appWidgetId, Context context){ mCurrentDisplay = currentDisplay; mViews = widgetRemoteViews; mDisplayManager = displayManager; mAppWidgetManager = appWidgetManager; mAppWidgetId = appWidgetId; mContext = context; MiracastApplication application = (MiracastApplication) mContext.getApplicationContext(); mTracker = application.getDefaultTracker(); }
Example #13
Source File: ScreenCaptureUtilByMediaPro.java From RobotHelper with GNU Affero General Public License v3.0 | 5 votes |
public static void init() { sMediaProjection = mProjectionManager.getMediaProjection(resultCode, data); //start capture reader mImageReader = ImageReader.newInstance(MainApplication.sceenWidth, MainApplication.sceenHeight, PixelFormat.RGBA_8888, 2); mVirtualDisplay = sMediaProjection.createVirtualDisplay( "ScreenShot", MainApplication.sceenWidth, MainApplication.sceenHeight, MainApplication.dpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC, mImageReader.getSurface(), null, null); // mImageReader.setOnImageAvailableListener(reader -> { // Bitmap bitmap = null; // try (android.media.Image image = reader.acquireLatestImage()) { // if (image != null) { // bitmap = covetBitmap(image); //// if (ScreenCaptureUtil.screenCache != null) { //// ScreenCaptureUtil.screenCache.recycle(); //// } // ScreenCaptureUtil.screenCache = bitmap; // } // } catch (Exception e) { // e.printStackTrace(); // } // // }, getBackgroundHandler()); }
Example #14
Source File: WatchFaceActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the display manager and register a listener (this activity). displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); // displayManager.registerDisplayListener(this, null); }
Example #15
Source File: ScreenOnService.java From SecondScreen with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { super.onHandleIntent(intent); // Turn the backlight back off after the device wakes up SharedPreferences prefCurrent = U.getPrefCurrent(this); SharedPreferences prefMain = U.getPrefMain(this); DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE); Display[] displays = dm.getDisplays(); if(!prefCurrent.getBoolean("not_active", true) && prefCurrent.getBoolean("backlight_off", false) && (displays[displays.length - 1].getDisplayId() != Display.DEFAULT_DISPLAY || prefMain.getBoolean("force_backlight_off", false))) { // Turn auto-brightness off so it doesn't mess with things Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); // Attempt to set screen brightness to 0 first to avoid complications later Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0); // Run superuser command to blank screen again after device was turned off for(File backlightOff : U.backlightOff) { if(backlightOff.exists()) { U.runCommand(this, "sleep 2 && echo 0 > " + backlightOff.getAbsolutePath()); break; } } } }
Example #16
Source File: ScreenCapturer.java From habpanelviewer with GNU General Public License v3.0 | 5 votes |
public synchronized Bitmap captureScreen() throws IllegalStateException { AtomicReference<Image> imageHolder = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); ImageReader mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2); mImageReader.setOnImageAvailableListener(imageReader -> { imageHolder.set(mImageReader.acquireLatestImage()); latch.countDown(); }, mHandler); VirtualDisplay display = mProjection.createVirtualDisplay("screen-mirror", mWidth, mHeight, mDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC, mImageReader.getSurface(), null, null); try { latch.await(1, TimeUnit.SECONDS); if (latch.getCount() == 1) { throw new IllegalStateException("Screen capturing timed out"); } final Image image = imageHolder.get(); Image.Plane[] planes = image.getPlanes(); ByteBuffer buffer = planes[0].getBuffer(); int pixelStride = planes[0].getPixelStride(); int rowStride = planes[0].getRowStride(); int rowPadding = rowStride - pixelStride * mWidth; // create bitmap Bitmap bmp = Bitmap.createBitmap(mWidth + rowPadding / pixelStride, mHeight, Bitmap.Config.ARGB_8888); bmp.copyPixelsFromBuffer(buffer); image.close(); return bmp; } catch (InterruptedException e) { throw new IllegalStateException("Got interrupt while capturing screen"); } finally { display.release(); } }
Example #17
Source File: RecorderService.java From screenrecorder with GNU Affero General Public License v3.0 | 5 votes |
private VirtualDisplay createVirtualDisplay() { return mMediaProjection.createVirtualDisplay("MainActivity", WIDTH, HEIGHT, DENSITY_DPI, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mMediaRecorder.getSurface(), null /*Callbacks*/, null /*Handler*/); }
Example #18
Source File: HelperNotification.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private boolean isScreenOn(Context context) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { @SuppressLint("WrongConstant") DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); boolean screenOn = false; for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { screenOn = true; } } return screenOn; } else { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); } }
Example #19
Source File: Utils.java From aosp_screen_stabilization with Apache License 2.0 | 5 votes |
public static boolean isScreenOn(Context context) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) return true; } return false; }
Example #20
Source File: DesktopModeFragment.java From Taskbar with Apache License 2.0 | 5 votes |
@Override protected void loadPrefs() { // Add preferences addPreferencesFromResource(R.xml.tb_pref_desktop_mode); // Set OnClickListeners for certain preferences findPreference(PREF_DESKTOP_MODE).setOnPreferenceClickListener(this); findPreference(PREF_SET_LAUNCHER_DEFAULT).setOnPreferenceClickListener(this); findPreference(PREF_PRIMARY_LAUNCHER).setOnPreferenceClickListener(this); findPreference(PREF_DIM_SCREEN).setOnPreferenceClickListener(this); findPreference(PREF_ENABLE_ADDITIONAL_SETTINGS).setOnPreferenceClickListener(this); if(!U.isShowHideNavbarSupported()) { PreferenceCategory category = (PreferenceCategory) findPreference(PREF_ADDITIONAL_SETTINGS); category.removePreference(findPreference(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE)); } SharedPreferences pref = U.getSharedPreferences(getActivity()); if(pref.getBoolean(PREF_LAUNCHER, false)) { findPreference(PREF_DESKTOP_MODE).setEnabled(false); U.showToastLong(getActivity(), R.string.tb_disable_home_setting); } else bindPreferenceSummaryToValue(findPreference(PREF_DESKTOP_MODE)); bindPreferenceSummaryToValue(findPreference(PREF_DISPLAY_DENSITY)); DisplayManager manager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE); manager.registerDisplayListener(listener, null); updateAdditionalSettings(); }
Example #21
Source File: DesktopModeFragment.java From Taskbar with Apache License 2.0 | 5 votes |
@Override public void onDestroy() { DisplayManager manager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE); manager.unregisterDisplayListener(listener); super.onDestroy(); }
Example #22
Source File: SRManager.java From VMLibrary with Apache License 2.0 | 5 votes |
/** * 创建一个ImageReader VirtualDisplay */ private void createScreenShortVirtualDisplay() { VMLog.i("createScreenShortVirtualDisplay"); getScreenInfo(); initImageReader(); String virtualDisplayName = "ScreenShort"; int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; virtualDisplay = mediaProjection.createVirtualDisplay(virtualDisplayName, width, height, density, flags, imageReader .getSurface(), null, null); }
Example #23
Source File: ScreenRecordActivity.java From ScreenCapture with MIT License | 5 votes |
private VirtualDisplay createVirtualDisplay() { return mMediaProjection.createVirtualDisplay("MainActivity", DISPLAY_WIDTH, DISPLAY_HEIGHT, mScreenDensity, // DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC, mMediaRecorder.getSurface(), null /*Callbacks*/, null /*Handler*/); }
Example #24
Source File: OverlayDisplayWindow.java From V.FlyoutTest with MIT License | 5 votes |
public JellybeanMr1Impl(Context context, String name, int width, int height, int gravity) { super(context, name, width, height, gravity); mDisplayManager = (DisplayManager)context.getSystemService( Context.DISPLAY_SERVICE); mWindowManager = (WindowManager)context.getSystemService( Context.WINDOW_SERVICE); mDefaultDisplay = mWindowManager.getDefaultDisplay(); updateDefaultDisplayInfo(); createWindow(); }
Example #25
Source File: DisplayConnectionService.java From SecondScreen with Apache License 2.0 | 5 votes |
@Override public void onDisplayAdded(int displayId) { SharedPreferences prefCurrent = U.getPrefCurrent(DisplayConnectionService.this); DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE); Display[] displays = dm.getDisplays(); try { if(displays[displays.length - 2].getDisplayId() == Display.DEFAULT_DISPLAY && prefCurrent.getBoolean("not_active", true)) { Intent hdmiIntent = new Intent(DisplayConnectionService.this, HdmiActivity.class); hdmiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(hdmiIntent); } } catch (ArrayIndexOutOfBoundsException e) { /* Gracefully fail */ } }
Example #26
Source File: QPMScreenRecorderManager.java From QPM with Apache License 2.0 | 5 votes |
private void start(Activity activity, int resultCode, Intent data) { if (mediaProjectionManager == null) { return; } startTime = System.currentTimeMillis(); try { mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data); DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; int density = metrics.densityDpi; mediaRecorder = new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setOutputFile(getSaveFile()); mediaRecorder.setVideoSize(screenWidth, screenHeight); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mediaRecorder.setVideoEncodingBitRate(screenWidth * screenHeight); mediaRecorder.setVideoFrameRate(30); mediaRecorder.prepare(); display = mediaProjection.createVirtualDisplay(QPMScreenRecorderManager.class.getSimpleName(), screenWidth, screenHeight, density, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mediaRecorder.getSurface(), null, null); mediaRecorder.start(); } catch (Exception e){ e.printStackTrace(); onRecorderFailed(activity); } }
Example #27
Source File: ScreenCaptureFragment.java From media-samples with Apache License 2.0 | 5 votes |
private void setUpVirtualDisplay() { Log.i(TAG, "Setting up a VirtualDisplay: " + mSurfaceView.getWidth() + "x" + mSurfaceView.getHeight() + " (" + mScreenDensity + ")"); mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture", mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mSurface, null, null); mButtonToggle.setText(R.string.stop); }
Example #28
Source File: Utils.java From KernelAdiutor with GNU General Public License v3.0 | 5 votes |
public static boolean isScreenOn(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { return true; } } return false; } else { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return powerManager.isScreenOn(); } }
Example #29
Source File: ScreenUtils.java From Reader with Apache License 2.0 | 5 votes |
private static DisplayMetrics getEPDDisplayMetrics() { Context context = AppUtils.getAppContext(); DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); Display[] presentationDisplays = displayManager.getDisplays(); Display display; if (presentationDisplays.length > 1) { display = presentationDisplays[1]; } else { display = presentationDisplays[0]; } DisplayMetrics metrics = new DisplayMetrics(); display.getRealMetrics(metrics); LogUtils.d("widthPixels=" + metrics.widthPixels + " heightPixels=" + metrics.heightPixels); return metrics; }
Example #30
Source File: ChargeChangeReceiver.java From always-on-amoled with GNU General Public License v3.0 | 5 votes |
private boolean isDisplayOn(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { return true; } } return false; } else { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return powerManager.isScreenOn(); } }