Why file exists statement not true in android? -
i working email attachment .i facing 1 problem while attachment .problem want sent mail attachment .i have 1 file on path sdcard0 fgg hh.html.when debug on file file = new file(attachments.getstring(i));
show file:/storage/sdcard0/fgg/hh.html after not go if condition why ?
file file = new file(attachments.getstring(i)); if (file.exists()) { uri uri = uri.fromfile(file); uris.add(uri); }
here hole code
jsonarray attachments = parameters.getjsonarray("attachments"); if (attachments != null && attachments.length() > 0) { arraylist<uri> uris = new arraylist<uri>(); //convert paths android friendly parcelable uri's (int i=0; i<attachments.length(); i++) { try { file file = new file(attachments.getstring(i)); if (file.exists()) { uri uri = uri.fromfile(file); uris.add(uri); } } catch (exception e) { log.e("emailcomposer", "error adding attachment: " + e.tostring()); } } if (uris.size() > 0) { emailintent.putparcelablearraylistextra(intent.extra_stream, uris); } } } catch (exception e) { log.e("emailcomposer", "error handling attachments param: " + e.tostring()); }
uri file need triple slashes :
file:///storage/sdcard0/fgg/hh.html
as can see here. twill not work, try remove "file:" part of string :
file file = new file(attachments.getstring(i).replace("file:","");
Comments
Post a Comment