slender
slender

Reputation: 43

Can't View All Files In File Browser

I'm having this weird problem in a file browser app I made where I cannot view every file/folder that is actually there. It seems as if they are filtered out. Root explorer seems to find the files fine but my app can't. Any ideas? And yes my phone is rooted.

Upvotes: 2

Views: 367

Answers (2)

Reed
Reed

Reputation: 14984

The reason why the File class wasn't working is because you don't have permission to read those directories. The only way to get access is to read/write those directories is to use the root permissions - and to use the root permissions you must run linux-based commands.

I don't know how exactly to do the entire process, but you should use RootTools.

Normally to run a linux based command you would do Runtime.getRuntime.exec("command"); but with RootTools, the whole process is highly simplified, and it's easier to get the results of the command as well.

If you'd like I can try to explain further how to do it manually (doing Runtime.getRuntime.exec("command"); or if you browse the Wiki for RootTools and integrate it with your app, you will probably be able to figure that out.

If you have further questions, I'll be happy to help to my best abilities.

EDIT: I see your answer, so it appears that you have a good understanding now of how to run the commands. RootTools will make everything easier on you, though.

Upvotes: 1

slender
slender

Reputation: 43

Alright, I've looked into shell commands more, and this method works, but is this the most efficient way to do this?

public void ls(String directory) {  
                Process process = null;

                try {
                    process = Runtime.getRuntime().exec("ls " + directory);
                } catch (IOException e) {
                    e.printStackTrace();
                }    

                int read;
                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                char[] buffer = new char[4096];
                StringBuilder output = new StringBuilder();

                try {
                    while ((read = reader.read(buffer)) > 0) {
                        output.append(buffer, 0, read);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                try {
                    process.waitFor();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }       

                Log.d("Files", output.toString());
        }

Upvotes: 1

Related Questions