Read android system file
Asked Answered
B

1

4

I have tried many solutions to read files but no one were working. I need a method to read a system file and show the text in a toast or in a dialog. Of course my app has root permission. I have to show the content of "eoc_status" in a toast after a checkbox click.

For example;

Runtime.getRuntime().exec("/sys/kernel/abb-chargalg/eoc_status").getInputStream(); 

I need to open text files.

Bogey answered 26/3, 2014 at 10:44 Comment(5)
I'm afraid your going to need to provide some example code for the kind of thing you've tried and be a little more specific with what you need and why. For example, what do you mean by a 'system' file? That way it will be easier for people to help you and your question will be more useful for other people looking for an answer to a similar question.Pydna
For example this: Runtime.getRuntime().exec("/system/bin/getprop").getInputStream(); I need opening text FilesBogey
What file are you trying to retrieve? An actual system file (if so, which one?), or a file you have stored somewhere (if so, how did you store it?) in advance?Pydna
i have edited the main question.Bogey
What are the permissions of the file in question? If an app process is not allowed to read it, you would need to launch a helper process using a hacked su shim or similar.Matildamatilde
V
7

Assuming you do have read-access to eoc_status

You are going to want to read it, not exec it. ie use cat or use a FileReader:

Then you will want to do something (put it in your toast) with the returned InputStream.

For example:

    BufferedReader  buffered_reader=null;
    try 
    {
        //InputStream istream = Runtime.getRuntime().exec("cat /sys/kernel/abb-chargalg/eoc_status").getInputStream();
        //InputStreamReader istream_reader = new InputStreamReader(istream);
        //buffered_reader = new BufferedReader(istream_reader);
        buffered_reader = new BufferedReader(new FileReader("/sys/kernel/abb-chargalg/eoc_status"));
        String line;

        while ((line = buffered_reader.readLine()) != null) 
        {
            System.out.println(line);
        }           
    } 
    catch (IOException e) 
    {
        // TODO 
        e.printStackTrace();
    }
    finally 
    {
        try 
        {
            if (buffered_reader != null)
                buffered_reader.close();
        } 
        catch (IOException ex) 
        {
            // TODO 
            ex.printStackTrace();
        }
    }       
Voluntarism answered 26/3, 2014 at 11:44 Comment(1)
There is no point to launching cat as an executable, as you could do the reading directly from java. Launching an executable only makes sense if you are doing it by way of a hacked su that might function as a shim to run cat as root, in which case it would be able to do things the java program could not.Matildamatilde

© 2022 - 2024 — McMap. All rights reserved.