Skip to content Skip to sidebar Skip to footer

Store An Image In Internal Storage In Android

I am working now on application that start the camera and take a photo, I didn't use camera activity, but I wrote my camera app and I want to save the taken image in the internal p

Solution 1:

I don't know if this can help you but this is how I save a file to the SD card and it works.

publicvoidsaveToSD(Bitmap outputImage){


            File storagePath = new File(Environment.getExternalStorageDirectory() + "/MyPhotos/"); 
            storagePath.mkdirs(); 

            File myImage = new File(storagePath, Long.toString(System.currentTimeMillis()) + ".jpg");

            try { 
                FileOutputStream out = new FileOutputStream(myImage); 
                outputImage.compress(Bitmap.CompressFormat.JPEG, 80, out); 
                out.flush();    
                out.close();
            } catch (Exception e) { 
                e.printStackTrace(); 
            }               
        }

Solution 2:

Why don't you use the camera activity and save images to internal storage by creating temp folder that has writable permission which allow other application to write to this folder and take the image to its path and then after the camera activity return you can move the image to another internal storage folder but with private permission as follow

//the temp folder to start the camera activity withStringpath= getDir("images", Context.MODE_WORLD_WRITEABLE).getPath() + "/test.jpg";

//start the camera activityFilefile=newFile(path);
UrioutputFileUri= Uri.fromFile(file);

Intentintent=newIntent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_ACTIVITY);

and in onActivityResult method move it to folder with private permission it will work fine as I tested it

Post a Comment for "Store An Image In Internal Storage In Android"