diff --git a/app/release/PseudoSpeedTest_dic1911.apk b/app/release/PseudoSpeedTest_dic1911.apk
new file mode 100644
index 0000000..9a809fa
Binary files /dev/null and b/app/release/PseudoSpeedTest_dic1911.apk differ
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
deleted file mode 100644
index 38304fa..0000000
Binary files a/app/release/app-release.apk and /dev/null differ
diff --git a/app/src/main/java/moe/dic1911/test4speed/MainActivity.java b/app/src/main/java/moe/dic1911/test4speed/MainActivity.java
index ec22176..1e2f1f5 100644
--- a/app/src/main/java/moe/dic1911/test4speed/MainActivity.java
+++ b/app/src/main/java/moe/dic1911/test4speed/MainActivity.java
@@ -1,5 +1,6 @@
package moe.dic1911.test4speed;
+import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -19,13 +20,21 @@ public class MainActivity extends AppCompatActivity {
private Button btn_run, btn_svc;
private NetworkService svc;
- private boolean svcStarted;
+ private static boolean svcStarted;
+ private static Intent svcIntent;
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ svcStarted = isServiceRunning(NetworkService.class);
+ btn_svc.setText(svcStarted ? getString(R.string.stop_svc) : getString(R.string.start_svc));
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- svcStarted = false;
+ svcStarted = isServiceRunning(NetworkService.class);
btn_run = findViewById(R.id.btn_run);
btn_svc = findViewById(R.id.btn_svc);
btn_run.setOnClickListener(new View.OnClickListener() {
@@ -35,17 +44,31 @@ public void onClick(View v) {
}
});
- // not working rn
- btn_svc.setEnabled(!svcStarted);
+ if (svcIntent == null) svcIntent = new Intent(getApplicationContext(), NetworkService.class);
+ //btn_svc.setEnabled(!svcStarted);
btn_svc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!svcStarted) {
- getApplicationContext().startService(new Intent(getApplicationContext(), NetworkService.class));
- svcStarted = true;
- btn_svc.setEnabled(!svcStarted);
+ getApplicationContext().startService(svcIntent);
+ //btn_svc.setEnabled(!svcStarted);
+ } else {
+ getApplicationContext().stopService(svcIntent);
}
+ svcStarted = !svcStarted;
+ btn_svc.setText(svcStarted ? getString(R.string.stop_svc) : getString(R.string.start_svc));
}
});
}
+
+ // credit: Peter Mortensen and geekQ from StackOverflow
+ private boolean isServiceRunning(Class> serviceClass) {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (serviceClass.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/app/src/main/java/moe/dic1911/test4speed/NetworkService.java b/app/src/main/java/moe/dic1911/test4speed/NetworkService.java
index accccd1..f76ccc6 100644
--- a/app/src/main/java/moe/dic1911/test4speed/NetworkService.java
+++ b/app/src/main/java/moe/dic1911/test4speed/NetworkService.java
@@ -18,7 +18,7 @@
public class NetworkService extends Service {
- private static final int interval = 2 * 1000; // 2 min
+ private static final int interval = 90 * 1000; // 1.5 min
private static final String CHANNEL_ID = "default";
private static android.app.Notification noti;
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index fcfbcaf..135a7f4 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -3,4 +3,5 @@
這只是一個簡單的App可以戳一下SpeedTest讓電信業者暫時解除限速,啟用服務之後要停用的話請使用Android的\"強制停止\"
執行
啟動服務
+ 停止服務
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1b8d98e..e26bc28 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -3,4 +3,5 @@
This is a simple app that make dummy request to SpeedTest for unleash your mobile data speed.\nUse "Force Stop" to stop the service for now.
Run Once
Start service
+ Stop service