我正在创建一个用于读取已保存的wifi密码的root应用程序。我需要制作一个逻辑来读取文件中的ssid和密码,而不是任何其他信息。我还没有到目前为止,我需要知道如何请求root权限:
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;
}
}
清单文件:
android.permission.READ_EXTERNAL_STORAGE” android.permission.WRITE_EXTERNAL_STORAGE“
我使用了这2个权限,但我仍然需要root,但不知道如何请求它?
答案 0 :(得分:-1)
root访问权限仅适用于有根电话,如果您已经是root手机,则无法确定是否需要请求权限。