FileNotFound when opening picture in Android -


i'm building app needs open picture made camera. followed official android guide , did said, keep getting error message:

unable decode stream: java.io.filenotfoundexception: file:/storage/emulated/0/pictures/jpeg_test_-1259913402.jpg: open failed: enoent (no such file or directory) 

my code looks this:

private void dispatchtakepictureintent() {     intent takepictureintent = new intent(mediastore.action_image_capture);     // ensure there's camera activity handle intent     if (takepictureintent.resolveactivity(getpackagemanager()) != null) {         // create file photo should go         file photofile = null;         try {             photofile = createimagefile();         } catch (ioexception ex) {             // error occurred while creating file             system.err.println("an error occurred: " + ex);         }         // continue if file created         if (photofile != null) {             takepictureintent.putextra(mediastore.extra_output, uri.fromfile(photofile));             startactivityforresult(takepictureintent, request_image_capture);         }     } }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == request_image_capture && resultcode == result_ok) {         //try {             bitmap imagebitmap = bitmapfactory.decodefile(mcurrentphotopath);             system.out.println(imagebitmap);             testviewer.setimagebitmap(imagebitmap);             //bc = new bardecoder(imagebitmap);         //} catch (notfoundexception | formatexception e){           //  system.err.println("an error occurred: " + e);         //}     } else {         system.out.println("cancelled!");     } }  public void scanimage(view view){     dispatchtakepictureintent(); }  private file createimagefile() throws ioexception {     // create image file name     string timestamp = "test";     string imagefilename = "jpeg_" + timestamp + "_";     file storagedir = environment.getexternalstoragepublicdirectory(environment.directory_pictures);     file image = file.createtempfile(             imagefilename,  /* prefix */             ".jpg",         /* suffix */             storagedir      /* directory */     );      // save file: path use action_view intents     mcurrentphotopath = "file:" + image.getabsolutepath();     system.out.println("created!!");     return image; } 

i can see pictures indeed created when using file explorer, app can't find them. included these permissions in manifest file:

<uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.read_external_storage" /> 

any ideas on what's wrong?

fixed problem removing "file:" mcurrentphotopath. android's official guide says necessary, apparently doesn't work!


Comments