Skip to content Skip to sidebar Skip to footer

How Can I Specify The Taken Image Quality On Android?

I found these two part of code, to how to take a photo from the camera in Android: Inside the onCreate() method: Button capture; capture.setOnClickListener(new Vie

Solution 1:

Check below solution for your problem.

 public static File IMAGE_PATH = null;
     public static final int CAMERA_REQUEST = 100;
         private void openCameraApp(Context mContext) {
            Intent picIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);


            String file_path = Environment.getExternalStorageDirectory().toString() +
                    "/" + mContext.getResources().getString(R.string.app_name);

            File dir = new File(file_path);
            if (!dir.exists())
                dir.mkdirs();
            IMAGE_PATH = new File(dir, mContext.getResources().getString(R.string.app_name) +  System.currentTimeMillis() + ".png");


            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                picIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(mContext, mContext.getPackageName()+".fileprovider", IMAGE_PATH));
            }
            else {
                picIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(IMAGE_PATH));
            }

            ((Activity) mContext).startActivityForResult(picIntent, CAMERA_REQUEST);

        }

Post a Comment for "How Can I Specify The Taken Image Quality On Android?"