How install/uninstall APK programmaticaly in android?

Viewed 21

When I deleted this program I want to delete sqlite localdatabase in download files. I can clear cache from app but sqlite files didn't clean in download files.

public void cleanData(){

    try {
        // clearing app data
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("pm clear myPackageName");
        startActivity(new Intent(Intent.ACTION_DELETE).setData(Uri.parse("package:myPackageName")));

        deleteApks();

    } catch (Exception e) {
        e.printStackTrace();
    }
}


public void deleteApks(){

    String dbpath = String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    File fileList = new File(dbpath);


    if (fileList != null){

        File[] filenames = fileList.listFiles();
        System.out.println(filenames);

        for (File tmpf : filenames){
            System.out.println(tmpf.getName());
            if(tmpf.getName().contains("myAppName") || tmpf.getName().contains("sqliteDatabaseName"))
                tmpf.delete();

        }
    }
}
0 Answers
Related