我有两个主要问题。
卸载应用程序时,数据库不会删除。
在应用程序不稳定时,下载的文件不会被删除。
我的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://img.androidcookie.com/android/+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
请帮帮我。 抱歉英语不好。
在Android 6.0中,谷歌添加了一项名为“自动备份”的新function。
当此选项打开时(默认打开),Android系统几乎会复制系统创建的每个目录和文件,并将其上传到用户的google云端硬盘帐户。
当用户重新安装应用程序时,android会自动恢复应用程序的数据,无论它是如何安装的(通过Play商店,adb安装,初始设备设置)。
安装APK后,但在应用程序可供用户启动之前,还原操作会发生。
android开发者页面: https : //developer.android.com/guide/topics/data/autobackup.html
当我在寻找与GreenDao相关的类似问题的解决方案时,我突然解决了这个问题 – 这里稍微深入一些答案,但基本上如果您在api 23上需要将allowBackup设置为false以便能够依赖于数据库卸载时清除
看看这个SO答案:
删除应用程序时,Sqlite数据库会发生什么
您的数据库是否有效(除了在删除应用程序时不删除)?
如果它无法正常工作,您可能需要查看:
虽然这不一定与您的问题有关,但您可能需要考虑为数据库创建open()和close()并在每个中使用SQLiteOpenHelper对象 – 在open() ,您将使用sqliteopenhelperObj.getWriteableDatabase()并在close()你会使用sqliteopenhelperObj.close() 。
编辑:
如果您在测试应用程序的过程中将文件下载到设备,并且要删除它们,则可以使用Android Studio中的设备监视器https://developer.android.com/tools/help/monitor.html有一个文件管理器,可以让您查看和编辑设备上的文件。 您也可以在命令行上使用ADB(Android Debug Bridge)执行此操作https://developer.android.com/tools/help/adb.html
可以通过在AndroidManifest.xml设置android:allowBackup="false"来禁用自动备份
如果这是个人帐户,您需要删除备份以进行测试,则可以转到您的帐户的drive.google.com并导航到备份部分。
选择备份,您可以选择删除特定设备的备份: