Android卸载不删除sqlite,sqlite-卸载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

请帮我。 对不起,英语不好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值