List of usage examples for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_PUBLIC
int VIRTUAL_DISPLAY_FLAG_PUBLIC
To view the source code for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_PUBLIC.
Click Source Link
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static ImageReader createImageReader(Activity c) { DisplayMetrics metrics = c.getResources().getDisplayMetrics(); int density = metrics.densityDpi; int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; //DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; Display display = c.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size);// www .jav a 2 s . co m return ImageReader.newInstance(size.x, size.y, PixelFormat.RGB_565, 2); }
From source file:com.flyingcrop.ScreenCaptureFragment.java
public void saveImage() { if (mMediaProjection != null) { final Notification.Builder builder = new Notification.Builder(getActivity()) .setContentTitle(getResources().getString(R.string.fragment_saving_crop)) .setContentText(getResources().getString(R.string.fragment_wait)) .setSmallIcon(com.flyingcrop.R.drawable.ab_ico); final NotificationManager notificationManager = (NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); STORE_DIRECTORY = storage;//w w w . j a v a 2s . co m int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2); mMediaProjection.createVirtualDisplay("screencap", mWidth, mHeight, mScreenDensity, flags, mImageReader.getSurface(), new VirtualDisplayCallback(), mHandler); if (ServiceIsRunning()) { Intent mIntent = new Intent(getActivity(), Brush.class); getActivity().bindService(mIntent, mConnection, Context.BIND_AUTO_CREATE); } mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { image_available = true; Log.d("teste", "image_available : " + image_available.toString()); try { final long time_now = System.currentTimeMillis(); image = mImageReader.acquireLatestImage(); Log.i(TAG, "Time 1 " + (System.currentTimeMillis() - time_now)); if (image != null) { if (ServiceIsRunning()) { if (loop == 0) { View v = mServer.getView(); WindowManager wm = mServer.getWindowM(); if (v != null) wm.removeViewImmediate(v); else mServer.removeAllView(); } loop++; } if (!isFolder()) { Notification.Builder builder = new Notification.Builder(getActivity()) .setContentTitle(getResources().getString(R.string.fragment_error)) .setContentText(getResources().getString(R.string.fragment_error_access)) .setSmallIcon(com.flyingcrop.R.drawable.ab_ico); Toast.makeText(getActivity(), getResources().getString(R.string.fragment_error_toast), Toast.LENGTH_SHORT) .show(); NotificationManager notificationManager = (NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); getActivity().finish(); } savePlanes(); } } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } if (bitmap != null) { bitmap.recycle(); } if (image != null) { image.close(); } } } }, null); } }