diff --git a/app/src/main/java/net/nzbget/nzbget/Daemon.java b/app/src/main/java/net/nzbget/nzbget/Daemon.java index 938378e..2653ee9 100644 --- a/app/src/main/java/net/nzbget/nzbget/Daemon.java +++ b/app/src/main/java/net/nzbget/nzbget/Daemon.java @@ -2,7 +2,11 @@ import android.util.Log; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; public class Daemon { @@ -27,13 +31,33 @@ public Status status() { return Status.STATUS_NOTINSTALLED; } - else if (new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock").exists()) + + File lockFile = new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock"); + if (!lockFile.exists()) { - return Status.STATUS_RUNNING; - } - else { return Status.STATUS_STOPPED; } + + try + { + Process process = Runtime.getRuntime().exec("ps nzbget"); + BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); + int num = 0; + while (br.readLine() != null) + { + num++; + } + if (num > 1) + { + return Status.STATUS_RUNNING; + } + } + catch (IOException e) + { + // ignore + } + + return Status.STATUS_STOPPED; } public boolean exec(String cmdLine)