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

卸载Android应用程序时不会删除数据库,android,sqlite,android-sqlite,android-file,android-database,Android,Sqlite,Android Sqlite,Android File,Android Database,我有两个主要问题 卸载应用程序时不会删除数据库。 下载的文件在应用程序不稳定时不会删除。 我的android应用程序中有一个数据库。我用java创建它 class as follows. public DataBaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public DataBaseHelper(Context context, String name,

我有两个主要问题

卸载应用程序时不会删除数据库。 下载的文件在应用程序不稳定时不会删除。 我的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
请帮帮我。对不起,英语不好

看看这个答案: 在删除应用程序时,除了不删除外,您的数据库还能工作吗

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

虽然这不一定与您的问题有关,但您可能需要考虑为DB创建一个打开和关闭,并在每个打开的窗口中使用一个SqLeLeOpenHelpID对象,您将使用SqLeLeOpenHelpObj.GeWrreEdable数据库,并且在关闭时,您将使用SqLeLeOpenHelpObj.Relo. 编辑:

如果您在测试应用程序的过程中已将文件下载到设备上,并且希望删除这些文件,则可以使用Android Studio中的设备监视器。有一个文件管理器,允许您查看和编辑设备上的文件。您也可以使用ADB Android调试桥在命令行上执行此操作
在安卓6.0中,谷歌增加了一个名为自动备份的新功能

当这个选项打开时,Android系统会复制系统创建的几乎所有目录和文件,并将其上传到用户的google drive帐户

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

恢复操作发生在安装APK之后,但在用户可以启动应用程序之前

android开发者页面:

当我在寻找与GreenDao相关的类似问题的解决方案时,我遇到了这个问题-这里的答案稍微深入一些,但基本上,如果您的api 23上有问题,您需要将allowBackup设置为false,以便能够依赖于卸载时清除的数据库


通过在AndroidManifest.xml中设置android:allowBackup=false,可以禁用自动备份

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

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

亚行船壳道

也可以通过以下命令行执行此操作:

adb shell bmgr wipe com.google.android.gms/.backup.BackupTransportService com.example.app
您可以在此处找到与此命令相关的更多详细信息:

ADB外壳备份管理器的使用

可以在以下位置找到该命令的用法:


非常感谢,我会检查这个,如果有任何问题,我会尽快回复你。我也有同样的问题。我将DatabaseHelper更新为新版本,并以调试模式安装了该应用程序。在我完成新实现的功能后,我使用git返回了以前的一些提交,并尝试安装应用程序的旧版本。不幸的是,它不工作,因为应用程序总是给出错误,它不能降级数据库。如果我在安装旧版本之前手动删除了应用程序,甚至会出现此消息。因此,我得出的结论是,如果我卸载一个应用程序,数据库似乎不会被删除……真是令人沮丧和恼火。谢谢!这正是导致我的应用程序出现问题的原因。我通过将allowBackup设置为false关闭应用程序上的自动备份来修复此问题。这也正是我面临的问题。如果不是贴在这里的话,我不会意识到这一点。感谢仅在所有版本或6.0以上版本中遇到问题?谢谢,这很有用,但有点令人失望,因为您无法在那里进行每个应用的清理,但您必须删除整个设备的备份。我更新了答案,以提供一种方法,显示如何在每个应用的基础上进行清理。太好了!对答案和评论都投了赞成票。这是最有用的。谢谢此设置为false时无法生成应用程序。
    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'.");