android system camera returns picture (original)
Posted by pharcyde0 on Mon, 20 Jul 2020 16:29:32 +0200
Jurisdiction
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
Jump to Camera
private void intent_Carmer(){
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
}
String fileName = getPhotoFileName() + ".jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
path_carmer =path + fileName;
Uri uri = Uri.fromFile(new File(path_carmer));
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent,TAKE_PHOTO);
}
getPhotoFileName() returns the picture name (name here is time)
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
return "IMG_" + dateFormat.format(date);
}
path_carmer global string variable
private String path_carmer;
path Picture Save path (DCIM folder appears in this album)
private String path = Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_DCIM + File.separator;
TAKE_PHOTO Identifies Request
private static final int TAKE_PHOTO=1222;
After completing these steps, you are faced with an imageView display picture when the camera point is determined
case TAKE_PHOTO:
FileInputStream fis = null;
try {
fis=new FileInputStream(path_carmer);
Bitmap bitmap=BitmapFactory.decodeStream(fis);
img.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Displaying pictures must be in the OnActivityResult () method, which is overridden with three parameters
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
case is where I use switch to determine requestCode.
Note:
The picture is shown here at my address, so the data is empty
File operation to catch exceptions
Dynamic Load Rights if Mobile Phone is ANDROID 6.0 or above
Topics:
Android
Mobile