查看保存的wifi密码-root权限



我正在制作一个根应用程序,用于读取保存的wifi密码。我需要制定一个逻辑,只从文件中读取ssid和密码,而不读取任何其他信息。我还没有到目前为止,我需要知道如何请求root权限:

主要活动:

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;
}
}

清单文件:

android.permission.READ_EXTERNAL_STORAGE"android.permission.WRITE_EEXTERNAL_STORAGE">

我使用了这两个权限,但我仍然需要root,但不知道如何请求它?

root访问仅适用于root电话,如果已经是root电话,则不确定是否需要请求权限。

最新更新