我有两个主要问题。
卸载应用程序时数据库不会删除。
应用程序不稳定时,下载的文件不会删除。
我的android应用程序中有一个数据库。 我用java创建
class as follows.
public DataBaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public DataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
super(context, name, factory, version, errorHandler);
}
@Override
public void onCreate(SQLiteDatabase db) {
// creating required tables
db.execSQL(CREATE_TABLE_QUOTES);
db.execSQL(CREATE_TABLE_FILTERS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// on upgrade drop older tables
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUOTES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUOTES);
// create new tables
onCreate(db);
}
在数据库的代码中没有定义特定的路径。
这是我下载文件的代码。 并且有特定的路径,但是也不允许在Android> data> com.myapp中创建文件夹。
public String downloadImage(String img_url, int i) {
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/fog/images/filters");
// Make sure the Pictures directory exists.
dir.mkdirs();
File destinationFile = new File(dir, "filter"+i);
String filepath = null;
try{
URL url = new URL("http://fog.wrapper.io/uploads/category/"+img_url+".png");
HttpURLConnection conection = (HttpURLConnection)url.openConnection();
conection.setRequestMethod("GET");
conection.setRequestProperty("Content-length", "0");
conection.setUseCaches(false);
conection.setAllowUserInteraction(false);
conection.connect();
int status = conection.getResponseCode();
switch (status) {
case 200:
case 201:
FileOutputStream fileOutput = new FileOutputStream(destinationFile);
InputStream inputStream = conection.getInputStream();
int totalSize = conection.getContentLength();
int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 )
{
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength; Log.i("Progress:","downloadedSize:"+downloadedSize+"totalSize:"+ totalSize) ;
}
fileOutput.close();
if(downloadedSize==totalSize) filepath = destinationFile.getPath();
Log.i("filepath:"," "+filepath) ;
return filepath;
}
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
return null;
}
} // Get filters
请帮我。 对不起,英语不好。