android adb清除程序,adb - 清除android应用程序用户d

adb - 清除android应用程序用户d

使用adb shell清除应用程序数据

adb shell pm clear com.android.browser

但是从应用程序执行该命令时

String deleteCmd = "pm clear com.android.browser";

Runtime runtime = Runtime.getRuntime();

try {

runtime.exec(deleteCmd);

} catch (IOException e) {

e.printStackTrace();

}

问题:

虽然我已经给出了以下权限,但它不会清除用户数据也不会给出任何异常。

题:

如何使用adb shell清除应用程序数据?

8个解决方案

169 votes

这个命令对我有用:

adb shell pm clear packageName

Manmohan Soni answered 2019-08-06T19:09:36Z

5 votes

命令StreamReader需要root权限。

所以,先运行su。

以下是示例代码:

private static final String CHARSET_NAME = "UTF-8";

String cmd = "pm clear com.android.browser";

ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true).command("su");

Process p = pb.start();

// We must handle the result stream in another Thread first

StreamReader stdoutReader = new StreamReader(p.getInputStream(), CHARSET_NAME);

stdoutReader.start();

out = p.getOutputStream();

out.write((cmd + "\n").getBytes(CHARSET_NAME));

out.write(("exit" + "\n").getBytes(CHARSET_NAME));

out.flush();

p.waitFor();

String result = stdoutReader.getResult();

班级StreamReader:

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.concurrent.CountDownLatch;

class StreamReader extends Thread {

private InputStream is;

private StringBuffer mBuffer;

private String mCharset;

private CountDownLatch mCountDownLatch;

StreamReader(InputStream is, String charset) {

this.is = is;

mCharset = charset;

mBuffer = new StringBuffer("");

mCountDownLatch = new CountDownLatch(1);

}

String getResult() {

try {

mCountDownLatch.await();

} catch (InterruptedException e) {

e.printStackTrace();

}

return mBuffer.toString();

}

@Override

public void run() {

InputStreamReader isr = null;

try {

isr = new InputStreamReader(is, mCharset);

int c = -1;

while ((c = isr.read()) != -1) {

mBuffer.append((char) c);

}

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (isr != null)

isr.close();

} catch (IOException e) {

e.printStackTrace();

}

mCountDownLatch.countDown();

}

}

}

fantouch answered 2019-08-06T19:10:16Z

4 votes

Afaik浏览器应用程序数据不能清除其他应用程序,因为它存储在private_mode中。因此执行此命令可能probalby仅适用于root设备。 否则你应该尝试另一种方法。

Thkru answered 2019-08-06T19:09:17Z

2 votes

要清除应用程序数据请尝试这种方式。

public void clearApplicationData() {

File cache = getCacheDir();

File appDir = new File(cache.getParent());

if (appDir.exists()) {

String[] children = appDir.list();

for (String s : children) {

if (!s.equals("lib")) {

deleteDir(new File(appDir, s));Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");

}

}

}

}

public static boolean deleteDir(File dir) {

if (dir != null && dir.isDirectory()) {

String[] children = dir.list();

for (int i = 0; i < children.length; i++) {

boolean success = deleteDir(new File(dir, children[i]));

if (!success) {

return false;

}

}

}

return dir.delete();

}

Md Abdul Gafur answered 2019-08-06T19:10:40Z

0 votes

你好UdayaLakmal,

public class MyApplication extends Application {

private static MyApplication instance;

@Override

public void onCreate() {

super.onCreate();

instance = this;

}

public static MyApplication getInstance(){

return instance;

}

public void clearApplicationData() {

File cache = getCacheDir();

File appDir = new File(cache.getParent());

if(appDir.exists()){

String[] children = appDir.list();

for(String s : children){

if(!s.equals("lib")){

deleteDir(new File(appDir, s));

Log.i("TAG", "File /data/data/APP_PACKAGE/" + s +" DELETED");

}

}

}

}

public static boolean deleteDir(File dir) {

if (dir != null && dir.isDirectory()) {

String[] children = dir.list();

for (int i = 0; i < children.length; i++) {

boolean success = deleteDir(new File(dir, children[i]));

if (!success) {

return false;

}

}

}

return dir.delete();

}

}

请检查一下,让我知道......

您可以从这里下载代码

Mehul Patel answered 2019-08-06T19:11:18Z

-2 votes

// To delete all the folders and files within folders recursively

File sdDir = new File(sdPath);

if(sdDir.exists())

deleteRecursive(sdDir);

// Delete any folder on a device if exists

void deleteRecursive(File fileOrDirectory) {

if (fileOrDirectory.isDirectory())

for (File child : fileOrDirectory.listFiles())

deleteRecursive(child);

fileOrDirectory.delete();

}

My God answered 2019-08-06T19:11:35Z

-2 votes

adb uninstall com.package.packagename

在ADB shell上执行此命令。

adb uninstall com.package.packagename -k

-k将保留用户数据

Abhay Shiro answered 2019-08-06T19:12:20Z

-4 votes

如果您想手动执行,那么您也可以通过单击Settings–>Applications–>Manage Aplications–>中的“Clear Data”按钮清除用户数据

or Is there any other way to do that?

然后在这里下载代码

zZTCy.png

Mehul Patel answered 2019-08-06T19:12:53Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
启动 adb server 命令:adb start-server 停止 adb server 命令:adb kill-server 查询已连接设备/模拟器:adb devices 该命令经常出现以下问题: offline —— 表示设备未连接成功或无响应; device —— 设备已连接; no device —— 没有设备/模拟器连接; List of devices attached 设备/模拟器未连接到 adb 或无响应 查看应用列表: 查看所有应用列表:adb shell pm list packages 查看系统应用列表:adb shell pm list packages -s 查看第三方应用列表:adb shell pm list packages -3: 安装apk:adb install “-lrtsdg” “path_to_apk” “-lrtsdg”: -l:将应用安装到保护目录 /mnt/asec; -r:允许覆盖安装; -t:允许安装 AndroidManifest.xml 里 application 指定 android:testOnly=“true” 的应用; -s:将应用安装到 sdcard; -d:允许降级覆盖安装; -g:授予所有运行时权限; path_to_apk:apk的绝对路径。 示例安装淘宝apk:adb install -t C:data/local/tmp/taobao.apk 卸载apk:adb shell pm uninstall -k “packagename” “packagename”:表示应用的包名,以下相同; -k 参数可选,表示卸载应用但保留数据和缓存目录。 示例卸载 手机淘宝:adb uninstall com.taobao.taobao 清除应用数据与缓存命令:adb shell pm clear “packagename” 相当于在设置里的应用信息界面点击「清除缓存」和「清除数据」。 示例:adb shell pm clear com.taobao.taobao 表示清除 手机淘宝数据和缓存。 Android四大组件有Activity,Service服务,Content Provider内容提供,BroadcastReceiver广播接收器,具体不做多讲,常用的有以下: 查看前台 Activity命令:adb shell dumpsys activity activities | findstr “packagename” 查看正在运行的 Services命令:adb shell dumpsys activity services “packagename” 其中参数不是必须的,指定 “packagename” 表示查看与某个包名相关的 Services,不指定表示查看所有 Services。 查看应用详细信息命令:adb shell dumpsys package “packagename” 调起 Activity命令格式:adb shell am start [options] 例如:adb shell am start -n com.tencent.mm/.ui.LauncherUI表示调起微信主界面 调起 Service命令格式:adb shell am startservice [options] 例如:adb shell am startservice -n com.tencent.mm/.plugin.accountsync.model.AccountAuthenticatorService 表示调起微信的某 Service。 强制停止应用命令:adb shell am force-stop “packagename” 例如强制停止淘宝:adb shell am force-stop com.taobao.taobao 模拟按键指令:adb shell input keyevent keycode 不同的 keycode有不同的功能:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值