Saturday, 15 February 2014

java - Camera not saving image -



java - Camera not saving image -

can tell me why code not saving image gallery anymore? had working @ point, changed somewhere else, , doesn't work.

private void openimageintent() { // determine uri of photographic camera image save. final file storagedir = environment .getexternalstoragepublicdirectory(environment.directory_dcim); final string fname = classname.getuniqueimagefilename(); final file sdimagemaindirectory = new file(storagedir, fname); outputfileuri = uri.fromfile(sdimagemaindirectory); // camera. final list<intent> cameraintents = new arraylist<intent>(); final intent captureintent = new intent( android.provider.mediastore.action_image_capture); final packagemanager packagemanager = getpackagemanager(); final list<resolveinfo> listcam = packagemanager.queryintentactivities( captureintent, 0); (resolveinfo res : listcam) { final string packagename = res.activityinfo.packagename; final intent intent = new intent(captureintent); intent.setcomponent(new componentname(res.activityinfo.packagename, res.activityinfo.name)); intent.setpackage(packagename); intent.putextra(mediastore.extra_output, outputfileuri); cameraintents.add(intent); } // filesystem. final intent galleryintent = new intent(); galleryintent.settype("image/*"); galleryintent.setaction(intent.action_get_content); // chooser of filesystem options. final intent chooserintent = intent.createchooser(galleryintent, "chose source"); // add together photographic camera options. chooserintent.putextra(intent.extra_initial_intents, cameraintents.toarray(new parcelable[] {})); startactivityforresult(chooserintent, request_image_capture); } private static string getuniqueimagefilename() { // todo auto-generated method stub string filename = "img_" + system.currenttimemillis() + ".jpg"; homecoming filename; }

this error get:

10-29 23:53:50.692: e/bitmapfactory(12547): unable decode stream: java.io.filenotfoundexception: /file:/storage/emulated/0/dcim/img_1414623222659.jpg: open failed: enoent (no such file or directory) 10-29 23:53:50.692: e/bitmapfactory(12547): unable decode stream: java.io.filenotfoundexception: /file:/storage/emulated/0/dcim/img_1414623222659.jpg: open failed: enoent (no such file or directory)

final file storagedir = environment .getexternalstoragepublicdirectory(environment.directory_dcim);

you should set permission in android manifest write external storage

android storage broken on different version of android sdk. code work on devices not all.

the scheme cannot create file on scheme because of lack of permission giving error. best way have found see if external storage mounted create file on external.

there next 2 code snippets , both work.

environment.getexternalstoragedirectory() + "/" + "myimages" + "/someimage.jpg";

after can start media store update intent update android gallery.

or utilize code

final file dir = new file(context.getfilesdir() + "/nfs/guille/groce/users/nicholsk/workspace3/sqltest"); dir.mkdirs(); //create folders write files final file file = new file(dir, "blockfortest.txt");

java android

No comments:

Post a Comment