uri - Android: Saving taken picture to Imagefolder -


i want save picture in imagefolder in phone. have got 2 examples tried.

1. example

my app crashes when activate onclick method:

public void onclick(view arg0) {          intent cameraintent = new intent(android.provider.mediastore.action_image_capture);          startactivityforresult(cameraintent, 1337); }});  protected void onactivityresult(int requestcode, int resultcode, intent data)          {       if( requestcode == 1337)             {                 bitmap thumbnail = (bitmap) data.getextras().get("data");  mediastore.images.media.insertimage(getcontentresolver(),file.getabsolutepath(),file.getname(),file.getname());              }             else              {                 toast.maketext(androidcamera.this, "picture not taken", toast.length_long);             }             super.onactivityresult(requestcode, resultcode, data);         } 

2. example

before saved taken picture uri. saved picture in folder, can access on pc or fileapp. don´t know how can change path direction uri existing default image folder in phone.

uri uritarget = getcontentresolver().insert(media.external_content_uri,  new contentvalues()); 

this how manage saving images specified imagefolder

when starting camera intent define path , directory, image should saved, , pass intetn when starting camera:

    private void startcameraintent() {         //create file path         final string photostorepath = getproductphotodirectory().getabsolutepath();          //create file uri         final uri fileuri = getphotofileuri(photostorepath);          //create camera intent         final intent cameraintent = new intent(mediastore.action_image_capture);          //put file ure intetn - tell camera save file image         cameraintent.putextra(mediastore.extra_output, fileuri);         // start activity         startactivityforresult(cameraintent, request_code_photo_from_camera);          //start image scanne add photo gallery         addproductphototogallery(fileuri);     } 

and here of helper methods used in code above

    private file getproductphotodirectory() {         //get directory file should stored         return new file(environment.getexternalstoragepublicdirectory(                 environment.directory_pictures),                 "myphotodir");     }      private uri getphotofileuri(final string photostorepath) {          //timestamp used in file name         final string timestamp = new simpledateformat("yyyymmdd_hhmmss",               locale.us).format(new date());          // file uri timestamp         final uri fileuri = uri.fromfile(new java.io.file(photostorepath                + java.io.file.separator + "img_" + timestamp + ".jpg"));          return fileuri;     }      private void addproductphototogallery(uri photouri) {         //create media scanner intetnt         intent mediascanintent = new intent(intent.action_media_scanner_scan_file);          //set uri scan         mediascanintent.setdata(photouri);         //start media scanner discover new photo , display in gallery         this.sendbroadcast(mediascanintent);    } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -