java - Android how to use Environment.getExternalStorageDirectory() corretly -
android how use environment.getexternalstoragedirectory()
how can use environment.getexternalstoragedirectory() read/write image sd card ? or there better way it?
i did use source download e save image:
try { url url = new url(urlbaseimagem + icone); urlconnection conection = url.openconnection(); conection.connect(); // useful can show tipical 0-100% progress bar int lenghtoffile = conection.getcontentlength(); // // download file inputstream input = new bufferedinputstream(url.openstream(), 8192); // output stream //file sdcard = environment.getexternalstoragepublicdirectory(download_service); file sdcard = environment.getexternalstoragedirectory(); file directory = new file(sdcard.getabsolutepath() + "/cardapioweb/rest/"); if(directory.exists() == false){ directory.mkdirs(); } file outputfile = new file(directory, icone); outputstream output = new fileoutputstream(outputfile); byte data[] = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; // publishing progress.... // after onprogressupdate called //publishprogress(""+(int)((total*100)/lenghtoffile)); // writing data file output.write(data, 0, count); } // flushing output output.flush(); // closing streams output.close(); input.close(); log.w("cardapioweb:" , "imagem " + outputfile.tostring() + " salva no sdcard"); } catch (exception e) { log.e("error: ", e.getmessage()); }
i did use source load e show image:
file arq = new file(this.sdcard.getabsolutepath() + "/cardapioweb/rest/" + filialdatacollection.get(position).get(key_icone)); //verifica se imagem foi baixada com sucesso if(arq.exists() == true){ //deve exibir imagem sdcard file outputfile1 = new file(this.sdcard.getabsolutepath() + "/cardapioweb/rest/", filialdatacollection.get(position).get(key_icone)); drawable imagem = drawable.createfrompath(outputfile1.tostring()); holder.tvweatherimage.setimagedrawable(imagem); }
the above codes works fine on emulator (android virtual device) eclipse !!!! when generate apk , install on galaxy s4, app can not read images (no error generated). not display images. wrong?
put log in code see
outputfile1.tostring();
actually points to, expect?
personally, have used outputfile1.getabsolutepath(); not line below:
drawable imagem = drawable.createfrompath(outputfile1.tostring());
Comments
Post a Comment