java - Capture image with camera in android and save with a custom name -


i have create android application capture picture , save in sdcard folder,now want save image custom name.

import java.io.bytearrayoutputstream; import android.view.menu; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.os.bundle; import android.provider.mediastore; import android.view.view; import android.widget.button; import android.widget.imageview;  public class mainactivity extends activity {      private static final int camera_request = 1888;     private imageview imageview;      @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         this.imageview = (imageview) this.findviewbyid(r.id.imageview1);         button photobutton = (button) this.findviewbyid(r.id.button1);          photobutton.setonclicklistener(new view.onclicklistener()          {              @override             public void onclick(view v)              {                  intent cameraintent = new intent(                         android.provider.mediastore.action_image_capture);                 cameraintent.putextra(mediastore.extra_output,                         mediastore.images.media.external_content_uri.getpath());                 cameraintent.putextra(mediastore.extra_output, "new-photo-name.jpg");                 startactivityforresult(cameraintent, camera_request);             }         });     }      protected void onactivityresult(int requestcode, int resultcode, intent data)      {         if (requestcode == camera_request && resultcode == result_ok)          {             bitmap photo = (bitmap) data.getextras().get("data");             imageview.setimagebitmap(photo);             mediastore.images.media.insertimage(getcontentresolver(), photo,                     null, null);              bytearrayoutputstream baos = new bytearrayoutputstream();             photo.compress(bitmap.compressformat.jpeg, 100, baos);              byte[] b = baos.tobytearray();          }     } 

here code have used capturing image , save them in sd card folder,please me save image specific name eg:android.jpeg

file outfile = new file(environment.getexternalstoragedirectory(), "myname.jpeg"); fileoutputstream fos = new fileoutputstream(outfile); photo.compress(bitmap.compressformat.jpeg, 100, fos);  fos.flush(); fos.close(); 

you need add permission in android manifest.

<uses-permission android:name="android.permission.write_external_storage" /> 

the snippet save content of photo inside /sdcard name "myname.jpeg"


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -