Camera preview image data processing with Android L and Camera2 API

Combining a few answers into a more digestible one because @VP’s answer, while technically clear, is difficult to understand if it’s your first time moving from Camera to Camera2: Using https://github.com/googlesamples/android-Camera2Basic as a starting point, modify the following: In createCameraPreviewSession() init a new Surface from mImageReader Surface mImageSurface = mImageReader.getSurface(); Add that new surface as … Read more

How to refresh preview on Android Studio 2.2?

Refresh feature is not removed, it is there; It’s pretty simple to refresh: Click on the preview screen to make sure preview window has the focus and press R. It should display the progress in the right-top corner while refreshing. If it doesn’t work for any reason, switch to design tab and press R, it … Read more

How to WhiteList app in Doze mode Android 6.0

Add permission <uses-permission android:name=”android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS”/> request whitelist your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = getPackageName(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); if (!pm.isIgnoringBatteryOptimizations(packageName)) { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse(“package:” + packageName)); startActivity(intent); } }

Android – Camera preview is sideways

This issue appeared to start out as a bug with certain hardware see here but can be overcome by using the call to mCamera.setDisplayOrientation(degrees) available in API 8. So this is how I implement it: public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (isPreviewRunning) { mCamera.stopPreview(); } Parameters parameters = mCamera.getParameters(); … Read more