I read a lot of questions regarding this issue. Some of them are similar to what I experience; I tried the answers without any success. The code works on HTC Android 4.2 and does not work on Nexus 7 Android 4.4. I changed the storage directory to work with Android 4.4, so this is not a problem.
The purpose of the camera will never return if I use
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
and returns if I use
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
but it does not save the file.
Here is the complete code. Evoke intention
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(manager) != null) { try { final File photoFile = createImageFile(); if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
File name
private File createImageFile() throws IOException { if (mStorageDirectory == null) { createInitialStorageDirectory(); setupFolders(); mScrollList.notifyDataSetInvalidated(); } // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "slide_" + timeStamp; File storageDir = new File(mStorageDirectory); File image = File.createTempFile(imageFileName, ".jpg", storageDir); // image.setWritable(true, false); // Save a path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); return image; }
Callback function
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && resultCode == -1) { } }
Root directory plus save directory
static String mBasePath = "/slides/"; private String getRootDirectory() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { if (Build.VERSION.SDK_INT >= 19) return mView.getContext().getFilesDir() + mBasePath; else return Environment.getExternalStorageDirectory() + "/Android/data/com.hdms.manager" + mBasePath;
Any thoughts would be appreciated.