"top"などのコマンドを実行しようとしているアプリをビルドしています。 私はアンドロイド7.0で取り組んでいます。 私は古いAndroidのバージョンでは、このコードを試してみたが、私はヌガーでそれをしようとしたとき、私は許可の次のエラーを取得するには、拒否された:アプリケーション内でadbコマンドを実行するとPermissionが拒否される
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.matant.cmdlineapp, PID: 7662
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.RuntimeException: java.io.IOException: Cannot run program "adb shell top": error=13, Permission denied
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:88)
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.IOException: Cannot run program "adb shell top": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:62)
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:128)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:964)
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:62)
at com.example.matant.cmdlineapp.MainActivity$RunningTopCommand.doInBackground(MainActivity.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
私が実行していたコードは次のとおりです。
protected Void doInBackground(String... params) {
//Execution en BackGround
Log.d("BACKGROUND", "START");
Log.d("BACK PARAM 0", params[0]);
//Log.d("BACK PARAM 1", params[1]);
try {
// Executes the command.
//Process process = Runtime.getRuntime().exec("adb version");
ProcessBuilder processBuilder = new ProcessBuilder("adb shell top");
Process process = processBuilder.start();
// Reads stdout.
// NOTE: You can write to stdin of the command using
// process.getOutputStream().
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
Log.d("reader val: ",output.toString());
publishProgress(output.toString());
}
reader.close();
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
現在、この種のデータを読み取る方法はありませんか? –
おそらくそうではありません。 – fluffyBatman