0

I'm making a root application for reading saved wifi passwords. And I need to make a logic for reading just ssid and passwords from the file and not any other infos. I haven't got so far, I need to know how to request root permission:

MainActivity:

package com.externalstoragedemo;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class MainActivity extends AppCompatActivity {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (TextView) findViewById(R.id.textView);
        String line = "";

        if (isExternalStorageReadable() || isExternalStorageWriteable()) {
            String wifiFolder = "/data/misc/wifi";

            File wifiConf = new File(wifiFolder, "wpa_supplicant.conf");
            FileInputStream fis = null;
            StringBuilder sb = new StringBuilder();

            try{
                fis = new FileInputStream(wifiConf);
                InputStreamReader isr = new InputStreamReader(fis);
                BufferedReader bf = new BufferedReader(isr);


                while((line = bf.readLine()) != null){
                    sb.append(line);
                }

            }catch (IOException e){
                e.printStackTrace();
            }finally{
                if(fis != null){
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            textView.setText(line+sb);

        }
    }

    public boolean isExternalStorageReadable(){
        String state = Environment.getExternalStorageState();
        if(Environment.MEDIA_MOUNTED.equals(state) ||
                Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
        {
            return true;
        }
            return false;
    }

    public boolean isExternalStorageWriteable(){
        String state = Environment.getExternalStorageState();
        if(Environment.MEDIA_MOUNTED.equals(state)){
            return true;
        }
            return false;
    }

}

MANIFEST FILE:

android.permission.READ_EXTERNAL_STORAGE" android.permission.WRITE_EXTERNAL_STORAGE"

I used those 2 permissions but I still need root, but don't know how to request it?

SteveYo
  • 47
  • 1
  • 6

1 Answers1

-1

root access is only available for rooted phones, not sure if you need to ask for permission if it is already root phone.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • Yeah I know that, but I was wondering do I need to request root permission like when I request external write and read storage etc? Few years ago there was root permission available, but now it's gone. – SteveYo Aug 31 '17 at 09:50