Database won't remove when uninstall the Android Application

Viewed 34426

I have two major questions.

  1. Database won't delete when uninstall app.
  2. Downloaded files won't delete while unstable the app.

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.

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.

5 Answers

GUI WAY

If this is a personal account and you need to delete the backup for testing, you can go to drive.google.com for your account and navigate to the backups section.

Select a backup and you are given the option to delete the backups for a specific device:

Select backups and then a backup to delete

ADB SHELL WAY

You can also do this from the command line with the following:

adb shell bmgr wipe com.google.android.gms/.backup.BackupTransportService com.example.app

You can find more details related to this command here:

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

ADB SHELL BACKUP MANAGER USAGE

The usage for the command can be found here:

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'.");

The auto backup can be disabled by setting android:allowBackup="false" in AndroidManifest.xml

Related