I am working to create a db file in my application. Now I want to create the .db file on application installation just one time. When I open the app, it just check for the existence of the file.
How can we check for a .db file in sdcard and if it exists before installation than to delete the file.
You can check if file exists or not using following code
FileConnection fileConnection = (FileConnection)Connector.open("file:///SDCard/foldername/" + "databasename.db");
boolean result=fileConnection.exists();
if(result)
{
//database available
}else{
//database not available
}
and next you want to check this when application first time instalation using
CodeModuleListener listner=new CodeModuleListener() {
public void modulesDeleted(String[] moduleNames) {
// TODO Auto-generated method stub
}
public void modulesAdded(int[] handles) {
// TODO Auto-generated method stub
//here you can check if database available or not if available then delete
try{
URI myURI = URI.create("file:///SDCard/foldername/" + "database_name.db");
DatabaseFactory.delete(myURI);
}catch (Exception e) {
// TODO: handle exception
}
}
public void moduleDeletionsPending(String[] moduleNames) {
// TODO Auto-generated method stub
}
};
CodeModuleManager.addListener(this.getApplication(), listner);