---
title: "android应用程序中使用root权限"
author: "aking86"
date: "2012-03-21T06:00:08Z"
tags: []
categories: ["移动开发"]
slug: "android-root"
draft: false
lastmod: "2012-03-21T06:00:27Z"
id: 1459267
url: "https://aking86.iteye.com/blog/1459267"
---

要在android应用程序中使用root权限，那么运行程序的设备必须具有root权限。

    http://www.eoeandroid.com/code/2012/0320/973.html

 

写道

public static boolean runRootCommand(String command) {  
String TAG = "";  
Process process = null;  
DataOutputStream os = null;  
try {  
process = Runtime.getRuntime().exec("su");  
os = new DataOutputStream(process.getOutputStream());  
os.writeBytes(command + "\\n");  
os.writeBytes("exit\\n");  
os.flush();  
process.waitFor();  
} catch (Exception e) {  
Log.d(TAG,  
"the device is not rooted， error message： "  
\+ e.getMessage());  
return false;  
} finally {  
try {  
if (os != null) {  
os.close();  
}  
if (process != null) {  
process.destroy();  
}  
} catch (Exception e) {  
e.printStackTrace();  
}  
}  
return true;  
}