当前位置: 代码迷 >> Android >> 代码实现剔除系统应用
  详细解决方案

代码实现剔除系统应用

热度:34   发布时间:2016-04-28 07:46:55.0
代码实现删除系统应用
如题,程序是内置在手机里的,具有系统权限,现在想搞搞删除系统应用的功能
目前有这个想法,和命令删除系统应用一样,先rm system/app/xxx.apk  然后使用uninstall卸载
不过试了下  发现删除apk没成功 那后续的也就没戏了 
有知道或者做过的大神么   注意是代码里执行的  
android 系统应用

------解决方案--------------------
你写的那个命令就是可以的,不过在rm system/app/xxx.apk 前要加一句“chmod 777 system/app/xxx.apk”即给该目录下的文件有读写权限,另外不需要再用uninstall了,删除系统应用的apk就已经卸载应用了,关于root权限问题,2L的回答应该是正解
------解决方案--------------------

public class ScriptUtil {
    public static final String REMOVE_APP_LIMIT = "chmod 771 /data/app \n";
    public static final String ADD_APP_LIMIT = "chmod 551 /data/app \n";
    
public static final String TAG = "ScriptUtil";
/**
 * 输出信息接口的对象
 */
private ScriptHandler scriptHandler = null;
/**
 * Handler对象
 */
private Handler handler = null;
/**
 * 输入的命令
 */
private String strCommand = null;

/**
 * constructor
 * 
 * @param strCommand
 *            所执行的命令
 * @param scriptHandler
 *            输出信息接口对象
 */
public ScriptUtil(String strCommand, ScriptHandler scriptHandler) {
this.scriptHandler = scriptHandler;
this.strCommand = strCommand;
}

public ScriptUtil() {
// TODO Auto-generated constructor stub
}

/**
 * 关键方法:执行命令
 */
public void execCommand() {
handler = new Handler();
ShellCommandThread thread = new ShellCommandThread();
thread.start();
}

/**
 * 该线程进行io操作
 */
private class ShellCommandThread extends Thread {
/**
 * 进程对象
 */
private Process process = null;
/**
 * 正确信息缓冲流
 */
private BufferedReader brCorrect = null;
/**
 * 错误信息缓冲流
 */
private BufferedReader brError = null;

private DataOutputStream dos = null;
/**
 * 0:成功 非0:失败
 */
int code = -1;

@Override
public void run() {
try {
process = Runtime.getRuntime().exec("su");

dos = new DataOutputStream(process.getOutputStream());

dos.writeBytes(strCommand + " ");

brCorrect = new BufferedReader(new InputStreamReader(
process.getInputStream()));
brError = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
String strTemp = new String();

dos.flush();

dos.close();

StringBuffer strTempCorrect = new StringBuffer();
StringBuffer strTempError = new StringBuffer();
while ((strTemp = brCorrect.readLine()) != null) {
strTempCorrect = strTempCorrect.append(strTemp + "\n");
}
strTemp = new String();
while ((strTemp = brError.readLine()) != null) {
strTempError = strTempError.append(strTemp + "\n");
}
code = process.waitFor();
Log.d(TAG, "code   :" + code);
Log.d(TAG, "strTempCorrect " + strTempCorrect.toString());
Log.e(TAG, "strTempError " + strTempError.toString());
handler.post(new ScriptRunnable(code,
strTempCorrect.toString(), strTempError.toString()));

} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
if (brCorrect != null) {
brCorrect.close();
brCorrect = null;
}
if (brError != null) {
brError.close();
brError = null;
}
if (dos != null) {
dos.close();
dos = null;
}
if (process != null) {
process = null;
}

} catch (IOException e) {
e.printStackTrace();
}
}
}
  相关解决方案