1

I am working on a project where I need to save images and videos in application internal memory only (not in SDCard or device Gallery). I am using below code. But this also save the image/video to device gallery. Please advice.

Bitmap bm;
        View v=imageview;
        v.setDrawingCacheEnabled(true);
        bm=Bitmap.createBitmap(v.getDrawingCache());
        v.setDrawingCacheEnabled(false);
        String fileName="image.png";        
        try 
        {
            FileOutputStream fOut=openFileOutput(fileName, MODE_PRIVATE);
            bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);

        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }   

I want to make the image and video private and secured. So I want to save them in apps internal memory. So no other app can access it. Please suggest.

Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107
  • look at this http://stackoverflow.com/a/7887114/964741 – RajaReddy PolamReddy Apr 22 '13 at 06:00
  • i dont understand. what do you mean by apps internal memory(not in sdcard or device gallery)? could you please tell me. – D'yer Mak'er Apr 22 '13 at 06:03
  • @RajaReddyPolamReddy This provide the mechanism to save the image in device SDCard. So all apps can access it. I want to make the image and video private and secured. So I want to save them in apps internal memory. So no other app can access it. Please suggest. – Sanchit Paurush Apr 22 '13 at 06:04
  • look at this http://developer.android.com/guide/topics/data/data-storage.html#filesInternal – RajaReddy PolamReddy Apr 22 '13 at 06:22
  • What type of device are you testing with? I know from experience that HTC pulls ALL images stored on the phone into the gallery, so you'll have to create your own method to delete it from the gallery in that specific case. – jonstaff Aug 07 '13 at 17:48

2 Answers2

3

Storing the images in internal memory, it will store the image on internal images folder.

                    Uri uriSavedImage;

                // the temp folder to start the camera activity with
                    String fileName = "image_" + String.valueOf(imageNum)+ ".png";
                    path = getDir("images", Context.MODE_WORLD_WRITEABLE).getPath() + "/" + fileName;
                    // start the camera activity
                    file = new File(path);
                    while (file.exists()) {
                        imageNum++;
                        fileName = "image_" + String.valueOf(imageNum)+ ".png";     
                        path = getDir("images_pho",Context.MODE_WORLD_WRITEABLE).getPath()+ "/" + fileName;
                        file = new File(path);
                    }
                    Uri ur = Uri.parse(file.toString());
                    uriSavedImage = Uri.fromFile(file);

            Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

            OutputStream imageFileOS;
            try {
                imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
                imageFileOS.write(data);
                imageFileOS.flush();
                imageFileOS.close();

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

hope its helps

Poovizhirajan N
  • 1,263
  • 1
  • 13
  • 29
0

As I told you, you can store the picture taken from the camera in the internal storage and immediately you can delete the taken image from the gallery with getContentResolver().delete(uri, null, null); or you can use this :

if (takenpicturefile.exists())
        if (takenpicturefile.delete())
            Log.d("tag","filedeleted");

Fore more details, you might need to refer this. Hope it helps.

Community
  • 1
  • 1
Kanth
  • 6,681
  • 3
  • 29
  • 41