Skip to content

Commit

Permalink
Kill BackgroundService at stop & update app after every 5 sec
Browse files Browse the repository at this point in the history
Signed-off-by: GauthamAsir <[email protected]>
  • Loading branch information
GauthamAsir committed Jun 7, 2020
1 parent 2f39fe3 commit f3a056e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="a.gautham.jiofistatus">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

<application
android:allowBackup="true"
Expand Down
49 changes: 27 additions & 22 deletions app/src/main/java/a/gautham/jiofistatus/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void run() {
new GetData().execute();
}
},0,10000);
}, 0, 50000);

}

Expand Down Expand Up @@ -113,39 +113,44 @@ protected void onPostExecute(Object o) {
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
}else if (progress<=40){
progressBar.setProgressTintList(ColorStateList.valueOf(Color.parseColor("#FFA500")));
}else if (progress<=60){
} else if (progress <= 60) {
progressBar.setProgressTintList(ColorStateList.valueOf(Color.parseColor("#CCCC00")));
}else if (progress<=80){
} else if (progress <= 80) {
progressBar.setProgressTintList(ColorStateList.valueOf(Color.parseColor("#198021")));
}else {
} else {
progressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN));
}

signal_strength_value.setText(network_signal);

if (network_signal.equals("Normal")){
signal_strength.setImageTintList(ColorStateList.valueOf(Color.BLUE));
}else if (network_signal.equals("Weak")){
signal_strength.setImageTintList(ColorStateList.valueOf(Color.RED));
}else {
signal_strength.setImageTintList(ColorStateList.valueOf(Color.GREEN));
switch (network_signal) {
case "Normal":
signal_strength.setImageTintList(ColorStateList.valueOf(Color.BLUE));
break;
case "Weak":
case "0":
signal_strength.setImageTintList(ColorStateList.valueOf(Color.RED));
break;
default:
signal_strength.setImageTintList(ColorStateList.valueOf(Color.GREEN));
break;
}

int up = Integer.parseInt(upSpeed.replace(" bps","")) / 1000;
int down = Integer.parseInt(dwSpeed.replace(" bps","")) / 1000;
int up = Integer.parseInt(upSpeed.replace(" bps", "")) / 1000;
int down = Integer.parseInt(dwSpeed.replace(" bps", "")) / 1000;

if (up==1000){
up = up/1000;
upload_speed.setText(String.format(Locale.ENGLISH,"%s mbps",up));
}else {
upload_speed.setText(String.format(Locale.ENGLISH,"%s kbps",up));
if (up >= 1000) {
up = up / 1000;
upload_speed.setText(String.format(Locale.ENGLISH, "%s mbps", up));
} else {
upload_speed.setText(String.format(Locale.ENGLISH, "%s kbps", up));
}

if (down==1000){
down = down/1000;
download_speed.setText(String.format(Locale.ENGLISH,"%s mbps",down));
}else {
download_speed.setText(String.format(Locale.ENGLISH,"%s kbps",down));
if (down >= 1000) {
down = down / 1000;
download_speed.setText(String.format(Locale.ENGLISH, "%s mbps", down));
} else {
download_speed.setText(String.format(Locale.ENGLISH, "%s kbps", down));
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package a.gautham.jiofistatus.receiver;

import android.app.ActivityManager;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import a.gautham.jiofistatus.service.BackgroundService;

public class ActionReceiver extends BroadcastReceiver {

@Override
Expand All @@ -19,7 +18,9 @@ public void onReceive(Context context, Intent intent) {

if (notificationManager != null) {
notificationManager.cancel(1);
new BackgroundService().stopService();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
assert am != null;
am.killBackgroundProcesses(context.getPackageName());
android.os.Process.killProcess(android.os.Process.myPid());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onCreate() {
public void run() {
getData();
}
},0,10000);
}, 0, 50000);
}

@Nullable
Expand All @@ -46,10 +46,6 @@ public IBinder onBind(Intent intent) {
return null;
}

public void stopService(){
stopSelf();
}

@Override
public void onDestroy() {
timer.cancel();
Expand Down

0 comments on commit f3a056e

Please sign in to comment.