如何以编程方式清除不同势的应用程序数据 [英] How to programatically clear a diffrent apps data

查看:134
本文介绍了如何以编程方式清除不同势的应用程序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想提出一个应用程序,清除当你点击一个按钮,Internet缓存。中,我希望它具有的权限,你清楚其他应用程序的数据。我曾尝试过许多不同的codeS和无法找到一个被用于此目的。是否有一个特殊权限,我需要或者是它甚至有可能。

am making a app that clears the internet cache when you click a button. In which i want it to have the permission you clear other app data. I have tried many different codes and cant find a one that is used for this purpose. Is there a special permission i need or is it even possible.

我已经试过这code在MainActivity.java但不能似乎得到它的工作:

I have tried this code in MainActivity.java but cant seem to get it to work:

private void clearPreferences() {
try {
    // clearing app data
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("pm clear com.android.browser");

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

}

任何帮助将是巨大的。谢谢!

Any help would be great. Thanks!

推荐答案

要清除它,你只需删除内容它的数据目录。有2个地点之一的SD,另一个内部。您可以清除一个在SD没有问题,只是使用<一href="http://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#deleteDirectory%28java.io.File%29"相对=nofollow> Apache的文件实用程序从阿帕奇共享,它具有一个函数来递归删除一个目录。内部目录需要root访问权限。或者是同一个用户。如果你做这两个应用程序,那么它应该是没有问题的,只要确保他们是通过设置的 sharedUserId参数。如果没有,那么你的应用程序只能工作作为根。 看到这个回答获取数据目录。

To clear it you simply delete the contents of it's data directory. There are 2 locations one on the SD, and another internally. You can clear the one on SD no problem, just use Apache FileUtils from Apache Commons, it has a function to delete a directory recursively. The internal dir requires root access. Or to be of same user. If you made both apps then it should be no problem just make sure they are the same user by setting sharedUserId parameter. If not, then your app could only work as root. See this answer to get data directory.

这是另一种生根,你可以打开的应用程序信息页面有问题的应用程序,并告诉用户通过点击就清楚数据及放手动清除该应用程序的数据;清除缓存按钮。

An alternative to rooting, you can open up the app info page for the app in question and tell the user to clear the app data manually by tapping on the clear data & clear cache buttons.

这篇关于如何以编程方式清除不同势的应用程序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆