android - How to store .vcf file in separate folder in internal SDCard -
i using next code store vcf
file generating code able generate vcf
file appears under root directory in sdcard want store under seperate folder how meet requirements? plz help you.
private void getvcardstring() throws ioexception { final string vfile = "backupcont" + currdate + ".vcf"; vcard = new arraylist<string>(); cursor = getcontentresolver().query( contactscontract.commondatakinds.phone.content_uri, null, null, null, null); cursor c = dbhandle.getcontactsbyischecked(); arraylist<string> arrchk=new arraylist<string>(); for(int cc=0;cc<c.getcount();cc++) { arrchk.add(c.getstring(c.getcolumnindex("con_name"))); } if (cursor != null && cursor.getcount() > 0) { int i; string new_path= environment.getexternalstoragedirectory().getabsolutepath()+"/folder_name"; // string path = "c:/"; file dir = new file(new_path); if (!dir.exists()) dir.mkdirs(); string storage_path = environment.getexternalstoragedirectory()+"/folder_name"+vfile; toast.maketext(getapplicationcontext(), storage_path,toast.length_long).show(); fileoutputstream mfileoutputstream = new fileoutputstream(storage_path, false); cursor.movetofirst(); (i = 0; < cursor.getcount(); i++) { if(arrchk.contains(cursor.getstring(cursor.getcolumnindex(contactscontract.commondatakinds.phone.display_name)))) { get(cursor); cursor.movetonext(); mfileoutputstream.write(vcard.get(i).tostring().getbytes()); } } mfileoutputstream.close(); cursor.close(); toast.maketext(getapplicationcontext(), "created...",toast.length_long).show(); uri uri=uri.fromfile(new file(storage_path,""+vfile)); intent sharingintent = new intent(intent.action_send); sharingintent.settype("application/x-vcard"); sharingintent.putextra(android.content.intent.extra_stream, uri); startactivity(intent.createchooser(sharingintent, "share using")); } else { log.d("tag", "no contacts in phone"); } }
string outputdirectory = environment.getexternalstoragedirectory().getabsolutepath() + file.separator + "subfoldername"; outputdirectory.mkdirs(); file outputfile = new file(outputdirectory, filename); fileoutputstream fos = new fileoutputstream(outputfile);
you should check environment.getexternalstoragestate().equals(environment.media_mounted)
ensure external storage in fact available.
android android-sdcard vcf
No comments:
Post a Comment