Android camera intends to create two files

I am making a program that takes a picture and then shows its thumbnail. When using the emulator, everything goes well, and the reset button deletes the photo. But on a real device, the purpose of the camera saves the image in the imageUri variable, and the second - as if I just opened the camera and took the picture myself.

private static final int CAMERA_PIC_REQUEST = 1337; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera); //start camera values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, "New Picture"); values.put(MediaStore.Images.Media.DESCRIPTION,"From your Camera"); imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); image = (ImageView) findViewById(R.id.ImageView01); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, CAMERA_PIC_REQUEST); //save the image buttons Button save = (Button) findViewById(R.id.Button01); Button close = (Button) findViewById(R.id.Button02); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) { try{ thumbnail = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri); image.setImageBitmap(thumbnail); } catch(Exception e){ e.printStackTrace(); } } else{ finish(); } } public void myClickHandler(View view) { switch (view.getId()) { case R.id.Button01: finish(); break; case R.id.Button02: dicard(); } } private void dicard(){ getContentResolver().delete(imageUri, null, null); finish(); } 
+5
android android-camera android-camera-intent
Dec 23 2018-10-12T00:
source share
1 answer

Some Android phones store the original photo in the gallery and thumbnails only at your location. It doesn't matter what you did with the initial request. I have two different HTC phones that do this, and many other brands that don't.

I decided it differently. I ran a request for each item in the gallery and loaded the BucketIDs into an array. I do this when the application launches the application for the camera. When the camera application returns, I make the same request (with items recently added to save time). I compare this to my original list and find the new BucketID. Then I compare the size of this image with the file that I explicitly set as output. If it is larger, I copy it, replacing what I had. Then I delete the file and delete it from the gallery.

Pain in you-know-what!

[EDIT] I had to change this again when I discovered a phone that did not save the unique bucket identifiers ... See my message in the link following this answer for more details.

+1
Jun 23 2018-11-11T00:
source share



All Articles