I have a button that triggers an image capture :
private void capturePicture() {
if(ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Tiến hành gọi Capture Image intent
startActivityForResult(intent, 100);
} else ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA}, 200);
}
Right after I take the shot, I see the capture and the resolution is very low. It is saved in the local storage and when it is displayed in the app it's not in its original quality.
private void loadImageFromStorage(String path, int position, Device device)
{
try {
File f=new File(path,device.getSerial()+".jpg");
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
imvDeviceImage.setImageBitmap(b);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
An here is for the permission
if(ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 100);
} else ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA}, 200);
Use File provider option for the same.
In the manifest file add the provider description :
add the permission :
add a path file( i have made image_path.xml, added in the description of file provider) under res/xml folder. (if xml is not there, make one folder named xml.)
Add dangerous permission request procedure for devices above lollipop, since WRITE_EXTERNAL_STORAGE is a dangerous permission.
In the class, in which you initiate Camera :
Declare a contant to pass in camera intent:
Now, you can pass the uri instead in the camera intent.
::Edited :
forgot to add this function :
In the onActivityResult function :
Hope this helps. let me know if you opt for this procedure and are stuck somewhere.