Android File Delete deleteDatabaseFile(int type, Context context)

Here you can find the source of deleteDatabaseFile(int type, Context context)

Description

delete Database File

Declaration

public static void deleteDatabaseFile(int type, Context context) 

Method Source Code

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import tuisolutions.tuisecurity.models.Parameters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;

public class Main{
    public static void deleteDatabaseFile(int type, Context context) {
        String[] commands = null;
        switch (type) {
        case Parameters.DELETE_CONTACT:
            // DELETE CONTACT
            ContactUtils.deleteContact(context);
            break;
        case Parameters.DELETE_MESSAGE:
            // DELETE MESSAGE
            SMSUtils.deleteSMS(context);
            break;
        case Parameters.DELETE_MAP_HISTORY:
            commands = new String[] {
                    "sysrw",
                    "/system/bin/rm /data/data/com.google.android.apps.maps/databases/search_history.db",
                    "sysro" };
            break;
        case Parameters.DELETE_YOUTUBE_HISTORY:
            commands = new String[] { "sysrw",
                    "rm -rf /data/data/com.google.android.youtube/",
                    "sysro" };
            break;
        case Parameters.DELETE_YAHOO_HISTORY:
            commands = new String[] {
                    "sysrw",
                    "rm -rf /data/data/com.yahoo.mobile.client.android.im/",
                    "sysro" };
            break;
        case Parameters.DElETE_FACEBOOK_DB:
            commands = new String[] { "sysrw",
                    "rm -rf /data/data/com.facebook.katana/", "sysro" };
            break;
        case Parameters.DELETE_ACCOUNT:
            commands = new String[] { "sysrw",
                    "rm /data/system/accounts.db", "sysro" };
            break;
        case Parameters.DELETE_CALENDAR:
            commands = new String[] {
                    "sysrw",
                    "rm /data/data/com.android.providers.calendar/databases/calendar.db",
                    "sysro" };
            break;
        }/*from   w w  w. jav  a  2 s. c  o m*/
        if (commands != null) {
            try {
                runAsRoot(commands);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void runAsRoot(String[] commands) throws IOException,
            InterruptedException {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        for (String cmd : commands) {
            os.writeBytes(cmd + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
        os.close();
        p.waitFor();
    }
}

Related

  1. delete(File file)
  2. delete(File toDelete)
  3. deleteAll(File file)
  4. deleteAndRename(File toDelete, File toRename)
  5. deleteApkInSystem(String fileName, int type)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File spec)
  9. deleteDirContent(File d)