0

I'm trying to add some code to help debugging an issue I've got with alarm/job scheduling on a user device, so that I can dump the current state of the alarms/jobs to a file for sending to me. I#m trying:

File outputFile;
String cmd;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    outputFile = new File(logDirectory, "jobs.txt");
    cmd = "adb shell dumpsys jobscheduler > " + outputFile;
} else {
    outputFile = new File(logDirectory, "alarms.txt");
    cmd = "adb shell dumpsys alarm > " + outputFile;
}
Runtime.getRuntime().exec(cmd);

But I'm getting:

java.io.IOException: Cannot run program "adb": error=13, Permission denied

Thing is, running the following command in the same place in the code is fine... outputs the log to a file, so clearly file writing permissions are granted:

File logFile = new File(logDirectory, "logs.txt");
cmd = "logcat -v time -f " + logFile + " *:V";
Runtime.getRuntime().exec(cmd);
2
  • Possible duplicate of Run adb on the device itself, i.e. as if it were the PC issuing the commands
    – kandroidj
    Commented Feb 17, 2019 at 15:08
  • @kandroidj why does the error say "permission denied" when running "adb" rather than command not found or something? Is there any way of querying the information that I need, i.e. alarms or jobs? I thought maybe the issue is that using the command I'm using also gets info for other apps, and hence the permission problem, but all I want is info for my own application anyway.
    – drmrbrewer
    Commented Feb 17, 2019 at 16:41

0

Browse other questions tagged or ask your own question.