I have copied the method from this question and modified a bit to use in my project. I have noticed, that when I call the method createNewFile() , the app ignores the rest of my method. How can i fix this?
public void exportDatabase(){
try{
File dbFile=getDatabasePath("Glukozko.db");
File exportDir = new File(Environment.getExternalStorageDirectory(), "");
if (!exportDir.exists()){
exportDir.mkdirs();
}
File file = new File(exportDir, "meritve.csv");
file.createNewFile(); //from this point on, the method is ignored
PrintWriter csvWrite = new PrintWriter(new FileWriter(file));
Cursor meritve=db.vrniMeritve();
if(meritve.getCount()==0){
Toast.makeText(MainActivity.this,"No data availible",Toast.LENGTH_SHORT).show();
}else{
while (meritve.moveToNext()){
String vrstica=meritve.getString(1)+";"+meritve.getString(2)+";"+meritve.getString(3)+";"+meritve.getString(4)+";"+meritve.getString(5)+";"+meritve.getString(6);
System.out.println(vrstica);
}
}
}catch (Exception e){
}
}
I have found the solution.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
I had to put this in the manifset file!