我有两个主要问题。卸载Android应用程序时数据库不会删除
- 数据库在卸载应用程序时不会被删除。
- 下载的文件不会在应用程序不稳定时被删除。
在我的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
请帮帮我。对不起,英文不好。
非常感谢你,我会检查这一点,并尽快回复您,如果有任何问题。 – KZoNE
我有同样的问题。我将我们的DatabaseHelper更新为新版本,并以调试模式安装了应用程序。在完成我新实现的功能后,我使用git返回了一些提交,然后尝试安装旧版本的应用程序。不幸的是,它不起作用,因为应用程序总是给出错误,它不能降级数据库。如果我在安装旧版本之前手动删除应用程序,甚至会出现此消息。所以我来到结果,数据库似乎并没有被删除,如果我卸载一个应用程序...真令人沮丧和烦人。 – jennymo