卸载Android应用程序时,数据库不会删除

KZo*_*oNE 44 sqlite android android-file android-sqlite android-database

我有两个主要问题.

  1. 卸载应用程序时,数据库不会删除.
  2. 在应用程序不稳定时,下载的文件不会被删除.

我的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);
}
Run Code Online (Sandbox Code Playgroud)

数据库代码中没有定义特定路径.

这是我下载文件的代码.并且有特定路径,但不允许在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
Run Code Online (Sandbox Code Playgroud)

请帮我.抱歉英语不好.

yeo*_*seo 99

在Android 6.0中,谷歌添加了一项名为"自动备份"的新功能.

当此选项打开时(默认打开),Android系统几乎会复制系统创建的每个目录和文件,并将其上传到用户的google云端硬盘帐户.

当用户重新安装应用程序时,android会自动恢复应用程序的数据,无论它是如何安装的(通过Play商店,adb安装,初始设备设置).

安装APK后,但在应用程序可供用户启动之前,还原操作会发生.

android开发者页面:https: //developer.android.com/guide/topics/data/autobackup.html

  • 谢谢!这正是导致我的应用程序出现问题的原因.我通过将allowBackup设置为false来关闭我的应用程序上的Auto Backup来修复此问题.<application android:allowBackup ="false"> (31认同)
  • 这正是我也遇到的问题。如果尚未在此处发布,将不会知道。谢谢 (2认同)

daz*_*000 11

贵路

如果这是个人帐户并且您需要删除备份以进行测试,您可以访问您的帐户的 drive.google.com 并导航到备份部分。

选择一个备份,您可以选择删除特定设备的备份:

选择备份,然后选择要删除的备份

亚行壳牌方式

您也可以使用以下命令从命令行执行此操作:

adb shell bmgr wipe com.google.android.gms/.backup.BackupTransportService com.example.app
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到与此命令相关的更多详细信息:

http://www.androiddocs.com/tools/help/bmgr.html#other

ADB Shell 备份管理器使用

该命令的用法可以在这里找到:

https://github.com/aosp-mirror/platform_frameworks_base/blob/6f357d3284a833cc50a990e14b39f389b8972254/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java#L443

    System.err.println("usage: bmgr [backup|restore|list|transport|run]");
    System.err.println("       bmgr backup PACKAGE");
    System.err.println("       bmgr enable BOOL");
    System.err.println("       bmgr enabled");
    System.err.println("       bmgr list transports");
    System.err.println("       bmgr list sets");
    System.err.println("       bmgr transport WHICH");
    System.err.println("       bmgr restore TOKEN");
    System.err.println("       bmgr restore TOKEN PACKAGE...");
    System.err.println("       bmgr restore PACKAGE");
    System.err.println("       bmgr run");
    System.err.println("       bmgr wipe TRANSPORT PACKAGE");
    System.err.println("");
    System.err.println("The 'backup' command schedules a backup pass for the named package.");
    System.err.println("Note that the backup pass will effectively be a no-op if the package");
    System.err.println("does not actually have changed data to store.");
    System.err.println("");
    System.err.println("The 'enable' command enables or disables the entire backup mechanism.");
    System.err.println("If the argument is 'true' it will be enabled, otherwise it will be");
    System.err.println("disabled.  When disabled, neither backup or restore operations will");
    System.err.println("be performed.");
    System.err.println("");
    System.err.println("The 'enabled' command reports the current enabled/disabled state of");
    System.err.println("the backup mechanism.");
    System.err.println("");
    System.err.println("The 'list transports' command reports the names of the backup transports");
    System.err.println("currently available on the device.  These names can be passed as arguments");
    System.err.println("to the 'transport' and 'wipe' commands.  The currently selected transport");
    System.err.println("is indicated with a '*' character.");
    System.err.println("");
    System.err.println("The 'list sets' command reports the token and name of each restore set");
    System.err.println("available to the device via the current transport.");
    System.err.println("");
    System.err.println("The 'transport' command designates the named transport as the currently");
    System.err.println("active one.  This setting is persistent across reboots.");
    System.err.println("");
    System.err.println("The 'restore' command when given just a restore token initiates a full-system");
    System.err.println("restore operation from the currently active transport.  It will deliver");
    System.err.println("the restore set designated by the TOKEN argument to each application");
    System.err.println("that had contributed data to that restore set.");
    System.err.println("");
    System.err.println("The 'restore' command when given a token and one or more package names");
    System.err.println("initiates a restore operation of just those given packages from the restore");
    System.err.println("set designated by the TOKEN argument.  It is effectively the same as the");
    System.err.println("'restore' operation supplying only a token, but applies a filter to the");
    System.err.println("set of applications to be restored.");
    System.err.println("");
    System.err.println("The 'restore' command when given just a package name intiates a restore of");
    System.err.println("just that one package according to the restore set selection algorithm");
    System.err.println("used by the RestoreSession.restorePackage() method.");
    System.err.println("");
    System.err.println("The 'run' command causes any scheduled backup operation to be initiated");
    System.err.println("immediately, without the usual waiting period for batching together");
    System.err.println("data changes.");
    System.err.println("");
    System.err.println("The 'wipe' command causes all backed-up data for the given package to be");
    System.err.println("erased from the given transport's storage.  The next backup operation");
    System.err.println("that the given application performs will rewrite its entire data set.");
    System.err.println("Transport names to use here are those reported by 'list transports'.");
Run Code Online (Sandbox Code Playgroud)


FLa*_*ash 6

自动备份可以通过设置来禁用它android:allowBackup="false"AndroidManifest.xml

  • 当此设置为“false”时,无法构建应用程序。 (2认同)

rob*_*low 5

  1. 看看这个SO答案:

删除应用程序后 Sqlite 数据库会发生什么

  1. 您的数据库是否工作(除了删除应用程序时不删除)?

  2. 如果它不能正常工作,您可能需要查看:

http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

尽管这不一定与您的问题相关,但您可能需要考虑为数据库创建一个open()and并在每个中使用一个对象- 在您将使用and in 中您将使用。close()SQLiteOpenHelperopen()sqliteopenhelperObj.getWriteableDatabase()close()sqliteopenhelperObj.close()

http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#close

编辑:

  1. 如果您在测试应用程序的过程中将文件下载到设备上,并且想要删除它们,可以使用 Android Studio 中的设备监视器https://developer.android.com/tools/help/monitor.html有一个文件管理器,可让您查看和编辑设备上的文件。您还可以使用 ADB(Android 调试桥)在命令行上执行此操作https://developer.android.com/tools/help/adb.html


Mic*_*el. 5

当我正在寻找与 GreenDao 相关的类似问题的解决方案时,我遇到了这个问题——这里有更深入的答案,但基本上如果你在 api 23 上,你需要将 allowBackup 设置为 false 才能依赖数据库卸载时被清除

/sf/answers/3013237951/