android - Camera Activity returns null URI -


i testing app on samsung note, here how used call camera

intent captureintent = new intent(mediastore.action_image_capture); startactivityforresult(captureintent, camera_capture); 

then in activity result:

protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (resultcode == result_ok)     {         if(requestcode == camera_capture)         {             picuri = data.getdata();             //continue code         }     } } 

but changed testing galaxy nexus , noticed data.getdata() returns null rather temp image uri. read couple of recommendations , mentioned passing file camera activity location of new iamge. changed code to:

.... file photofile = createimagefile(); //photofile = new file(environment.getexternalstoragedirectory(),  "pic.jpg"); captureintent.putextra(mediastore.extra_output, uri.fromfile(photofile)); startactivityforresult(captureintent, camera_capture); .... 

using method

private file createimagefile() throws ioexception {     string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date());     string imagefilename = "jpeg_" + timestamp + "_";     //file storagedir = environment.getexternalstoragepublicdirectory(environment.directory_pictures);     file storagedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "alboom");     //file storagedir = new file(getexternalfilesdir(environment.directory_pictures), "alboom");     //file storagedir = getexternalfilesdir(environment.directory_pictures);     //file storagedir = getfilesdir();  //not working     //file storagedir = getdir("mydir", context.mode_private);  //not working     //file storagedir = getcachedir();  //not working      if (!storagedir.mkdirs())   //required if creating new dir         log.e(tag, "directory not created");      //file image = file.createtempfile( imagefilename,  ".jpg", storagedir );     file image = new file(storagedir, imagefilename);        //file image = file.createtempfile(imagefilename, ".jpg");  //not working       // save file: path use action_view intents     mcurrentphotopath = "file:" + image.getabsolutepath();     return image; } 

and result handling

protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (resultcode == result_ok)     {         if(requestcode == camera_capture)         {             picuri = uri.fromfile(photofile);             //continue code         }     } } 

now code working when im writing external storage.. internal storage doesnt return camera activity.

my questions are:

  1. why cant write internal storage?
  2. how write "unhidden" image file external storage?
  3. why did old code stop working?

sometimes, despite of write this:

file source = null; source = new file(imageuri.getpath()); 

or:

uri url= uri.parse(stringpath); 

...it's possible obtain null value uri. seems related bug last android version (4.4.4). do, then? trick force new image saving in order refresh path:

 uri tempuri = getimageuri(getapplicationcontext(), imagebitmap); 

(...)

public uri getimageuri(context incontext, bitmap inimage) {   bytearrayoutputstream bytes = new bytearrayoutputstream();   inimage.compress(bitmap.compressformat.jpeg, 100, bytes);   string path = images.media.insertimage(incontext.getcontentresolver(), inimage, "title", null);   return uri.parse(path); } 

try it! can take @ this.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -