su访问android
我正在尝试创建一个文件浏览器(特别是我开始更改此:) 我的问题是:如何访问和查看目录“/”中的文件?我在那里找到了著名的:su访问android,android,root,su,Android,Root,Su,我正在尝试创建一个文件浏览器(特别是我开始更改此:) 我的问题是:如何访问和查看目录“/”中的文件?我在那里找到了著名的:Runtime.getRuntime().exec(“su”)但我只做超级用户授予管理员权限并停止工作 我按照此处的步骤创建根仿真器:。无论如何,我的手机是根和不工作 这是代码。应用程序位于超级用户列表中,但始终获取无法读取的邮件文件夹 public class AndroidExplorer extends ListActivity { private List<S
Runtime.getRuntime().exec(“su”)代码>但我只做超级用户授予管理员权限并停止工作
我按照此处的步骤创建根仿真器:。无论如何,我的手机是根和不工作
这是代码。应用程序位于超级用户列表中,但始终获取无法读取的邮件文件夹
public class AndroidExplorer extends ListActivity {
private List<String> item = null;
private List<String> path = null;
private String root="/";
private TextView myPath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<String> cmds = new ArrayList<String>();
cmds.add("mount -o rw,remount /system");
try {
doCmds(cmds);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myPath = (TextView)findViewById(R.id.path);
getDir(root);
}
public void doCmds(List<String> cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File file = new File(path.get(position));
if (file.isDirectory())
{
if(file.canRead())
getDir(path.get(position));
else
{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
else
{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
公共类AndroidExplorer扩展了ListActivity{
私有列表项=null;
私有列表路径=null;
私有字符串root=“/”;
私有文本视图myPath;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List cmds=new ArrayList();
添加(“装载-o rw,重新装载/系统”);
试一试{
doCmds(cmds);
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
myPath=(TextView)findViewById(R.id.path);
getDir(根);
}
public void doCmds(列表cmds)引发异常{
Process Process=Runtime.getRuntime().exec(“su”);
DataOutputStream os=新的DataOutputStream(process.getOutputStream());
用于(字符串tmpCmd:cmds){
os.writeBytes(tmpCmd+“\n”);
}
os.writeBytes(“退出”);
os.flush();
os.close();
process.waitFor();
}
私有void getDir(字符串dirPath)
{
setText(“位置:“+dirPath”);
item=newarraylist();
路径=新的ArrayList();
文件f=新文件(dirPath);
File[]files=f.listFiles();
如果(!dirPath.equals(root))
{
项。添加(根);
添加(根目录);
项目.添加(“/”);
add(f.getParent());
}
对于(int i=0;i
}
无论如何,我的手机是根和不工作
首先,你需要一部能正常工作的手机。根方法取决于您的手机型号,所以您需要在谷歌上搜索并找出它
一旦您成功地将手机设置为根目录,您将拥有超级用户权限,您将能够执行su
命令
您可以检查您的手机是否已按以下方式正确根目录(在windows命令提示符下):
您应该能够看到根文件夹上的文件,例如:
$ cd /
$ ls -al
编辑
替换:
Runtime r = Runtime.getRuntime();
process = r.exec("su");
以下是:
List<String> cmds = new List<String>();
cmds.add("mount -o rw,remount /system");
doCmds(cmds);
List cmds=new List();
添加(“装载-o rw,重新装载/系统”);
doCmds(cmds);
并添加以下功能:
public void doCmds(List<String> cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}
public void doCmds(列表cmds)引发异常{
Process Process=Runtime.getRuntime().exec(“su”);
DataOutputStream os=新的DataOutputStream(process.getOutputStream());
用于(字符串tmpCmd:cmds){
os.writeBytes(tmpCmd+“\n”);
}
os.writeBytes(“退出”);
os.flush();
os.close();
process.waitFor();
}
你的应用程序不能以root用户身份运行,它只能使用帮助程序可执行文件。谢谢Lukas,如果我的应用程序不能以管理员身份运行。。。我的应用程序如何在“/”中读写文件?谢谢你的回答!!,对不起,我没有解释清楚。我有一个带有氰mod的手机,因此它是扎根的。我在模拟器上安装了应用程序根资源管理器(v2.16)和超级用户,并且工作正常。我有根资源管理器的根访问权限,可以读写所有目录。我获取我的应用程序存储在超级用户的应用程序列表中(使用rootexplorer),我通过Runtime.getRuntime()获取它。Exec(“su”),但现在我无法读取、复制或删除任何文件。好的,当您尝试读取/复制/删除时会出现什么错误?试试“mount-orw,remount/system”你好,Caner,我已经编辑了这篇文章。我输入密码。该流程总是以“if(file.canRead())”的方式进行。如果我删除该条件,我会得到一个强制关闭:“应用程序已异常停止。请重试。例如,如果我使用rootexplorer转到“/data”,我可以看到其中的所有文件。但是,使用此应用程序,我会收到警报”文件夹无法读取!“仍然不起作用,请继续显示消息“无法读取文件”。我编辑了firstpost的代码,以便您可以看到我已更改并已测试。
public void doCmds(List<String> cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}