Tuesday, April 26, 2011

Re: [android-developers] Re: Built-in camera problem deleting files

1. For first option, if you provide more details , that will be helpful.

2. For second option. It will be better if you store the file into a directory in sd card instead of root directory. For example:
in /sdcard/TempDir/, there are two files
       .nomedia (empty file, to stop media scanner)
       youfile.jpg (you specified file)

3. Maybe camera saved another image that can be seen in gallery beside saving to your file. If this is true, you can delete your file safely with .nomedia protection. It will not influence the gallery.

Hope these are helpful. But camera implementation of different phones may differ. I'm not sure if above can work.

On Tue, Apr 26, 2011 at 6:42 PM, Fina Perez <fina.perezca@gmail.com> wrote:

Hi,
 that's what I'm using now, because I cannot make the first option
runs. But I'm having problems with the second option too..

_path = Environment.getExternalStorageDirectory() + ".nomedia";
Intent camara = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(_path);
Uri uri = Uri.fromFile(file);
camara.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(camara, CAMERA_PIC_REQUEST);

this is the code I'm using to "hide" the pictures I take with the
camera, but they still appear in the Gallery app, which is what I want
to avoid. And I want to avoid the mediascanner runs too...

Please, please, help!



On Apr 26, 10:28 am, Liang Wang <mr.lia...@gmail.com> wrote:
> Hi Fina,
>
> I think below code will work:
> Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
> startActivityForResult(intent, ...);
>
> Then you can handle the bitmap in onActivityResult().
>
> The code you mentioned is from android built-in Camera application. There
> you can see how camera app give result to you. From that you can get how to
> handle the result.
>
> On Tue, Apr 26, 2011 at 3:51 PM, Fina Perez <fina.pere...@gmail.com> wrote:
> > Hi Liang!
> > thanks a lot for your answer.
>
> > I was trying the first option but I'm having problems to tell the
> > camera that I want a bitmap. I tryed to use the method
> > "Inteng.#setType(String)" but I got an exception   And I don't know
> > where the code you wrote comes from, I mean Is that the way to ask for
> > a bitmap object as result? I thought it was more "intuitive" hehehe
>
> > On Apr 22, 11:56 am, Liang Wang <mr.lia...@gmail.com> wrote:
> > > 1. You can let camera return bitmap data, then you handle the data by
> > > yourself. There is no file saved this way.
>
> > > 2. If you let camera save the image to file in a specified
> > directory(through
> > > provider), making a empty file named .nomedia in that directory can
> > prevent
> > > mediascanner from scanning it. This way this image will not appear in
> > > gallery.
>
> > > See the code below in Camera:
> > >             if (mSaveUri != null) {
> > >                 OutputStream outputStream = null;
> > >                 try {
> > >                     outputStream =
> > > mContentResolver.openOutputStream(mSaveUri);
> > >                     outputStream.write(data);
> > >                     outputStream.close();
>
> > >                     setResult(RESULT_OK);
> > >                     finish();
> > >                 } catch (IOException ex) {
> > >                     // ignore exception
> > >                 } finally {
> > >                     Util.closeSilently(outputStream);
> > >                 }
> > >             } else {
> > >                 Bitmap bitmap = createCaptureBitmap(data);
> > >                 setResult(RESULT_OK,
> > >                         new Intent("inline-data").putExtra("data",
> > bitmap));
> > >                 finish();
> > >             }
>
> > > On Fri, Apr 22, 2011 at 4:51 PM, Fina Perez <fina.pere...@gmail.com>
> > wrote:
> > > > Hi!
>
> > > > I answer myself:
>
> > > > maybe is not the best solution but after deleting the file, this is
> > > > what I do:
>
> > > > sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
> > > > Uri.parse("file://" + Environment.getExternalStorageDirectory())));
>
> > > > we need to add this to the manifest:
> > > > <intent-filter>
> > > >  <action android:name="android.intent.action.MEDIA_MOUNTED" />
> > > >  <data android:scheme="file" />
> > > > </intent-filter>
>
> > > > (I found the solution here:
>
> > > >http://stackoverflow.com/questions/4430888/android-file-delete-leaves.
> > ..
> > > > )
>
> > > > On Apr 21, 11:32 am, Fina Perez <fina.pere...@gmail.com> wrote:
> > > > > Hi all!
>
> > > > > I'm using  the built-in camera in my app to take a picture and to
> > save
> > > > > it in a database. So, from my activity, I launch the camera, take a
> > > > > picture and go back to the activity (thanks to "onActivityResult"
> > > > > method). Here, I store the picture in the database and I delete it
> > > > > from the phone. Seems to be working properly: the picture is being
> > > > > deleted from the sdcard but if you go to the gallery app that comes
> > > > > with the device, the picture is being displayed but as a "wrong
> > file",
> > > > > so you can see that there is/was a picture there but you can't open
> > it
> > > > > or even see the preview.  But I can delete it from the gallery app
> > > > > manually (selecting them and then deleting). How can i do this
> > > > > programatically?
>
> > > > > Thanks a lot! I really need help with this
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to
> > android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscribe@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment