Note that there are some explanatory texts on larger screens.

plurals
  1. PODouble save image
    text
    copied!<p>I have used manual on <a href="http://developer.android.com/guide/topics/media/camera.html" rel="nofollow">http://developer.android.com/guide/topics/media/camera.html</a> but I have a problem with it. This code save image twice. First picture is saved in /sdcard/DCIM/Camera and the second picture is saved in /sdcard/PicturesMyCameraApp. How can I remove the first saving to /sdcard/DCIM/Camera. Thanks for help</p> <pre><code>public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.imageButton1: Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, getOutputMediaFileUri()); startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); break; } } @Override public boolean onCreateOptionsMenu(Menu menu){ MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.mainmenu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()) { case R.id.item1: /*Intent intent = new Intent(ZodiacActivity.this, AboutActivity.class); startActivity(intent);*/ break; case R.id.item2: this.moveTaskToBack(true); break; } return true; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode==CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode==RESULT_OK) { Toast.makeText(this, "Uloženo do: " + getOutputMediaFileUri().toString(), Toast.LENGTH_LONG).show(); } else { return; } } } public Uri getOutputMediaFileUri(){ return Uri.fromFile(getOutputMediaFile()); } public File getOutputMediaFile(){ // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload