卸载Android应用程序时数据库不会删除 [英] Database won't remove when uninstall the Android Application
问题描述
我有两个主要问题.
- 卸载应用程序时数据库不会删除.
- 不稳定的应用程序不会删除下载的文件.
我的android应用程序中有一个数据库.我是用Java创建的
There is a database in my android application. I create it by 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);
}
在代码中没有为数据库定义特定的路径.
There is no specific path defined at the code for database.
这是我下载文件的代码.并且有特定的路径,但是也不允许在Android> data> com.myapp中创建文件夹.
This is the code how I download files. And there is specific path, But it is not allowed to create folder in Android>data>com.myapp as well.
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
请帮助我.对不起,英语不好.
Please help me. Sorry for bad English.
推荐答案
,在Android 6.0中,谷歌添加了一项称为自动备份"的新功能.
in Android 6.0, google added new feature called Auto Backup.
启用此选项(默认为启用)时,Android系统几乎会复制系统创建的每个目录和文件,并将其上传到用户的Google驱动器帐户.
when this option is on(default is on), Android system copies almost every directories and files that created by system, and upload it to user's google drive account.
当用户重新安装应用程序时,无论安装方式如何(通过Play商店,adb安装,初始设备设置),android都会自动还原应用程序的数据.
When user reinstalls app, android automatically restore app's data, no matter how it was installed(via Play store, adb install, initial device setup).
还原操作在安装APK之后但在用户可以启动该应用之前进行.
The restore operation occurs after the APK is installed, but before the app is available to be launched by the user.
android开发人员页面: https://developer.android.com/guide/topics/data/autobackup.html
android developers page : https://developer.android.com/guide/topics/data/autobackup.html
这篇关于卸载Android应用程序时数据库不会删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!