Merge pull request #1302 from deltachat/foreground-notification

permanent foreground notification
This commit is contained in:
cyBerta
2020-04-21 18:48:07 +02:00
committed by GitHub
3 changed files with 1 additions and 44 deletions
@@ -48,7 +48,6 @@ public class ApplicationDcContext extends DcContext {
public static final int RECIPIENT_TYPE_CONTACT = 1;
public Context context;
public volatile boolean isScreenOn = false;
public ApplicationDcContext(Context context) {
super("Android "+BuildConfig.VERSION_NAME);
@@ -82,21 +81,7 @@ public class ApplicationDcContext extends DcContext {
BroadcastReceiver networkStateReceiver = new NetworkStateReceiver();
context.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver screenReceiver = new ScreenReceiver();
context.registerReceiver(screenReceiver, filter);
try {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
isScreenOn = pm.isScreenOn();
} catch (Exception e) {
}
if (!isScreenOn) {
KeepAliveService.startSelf(context);
}
KeepAliveService.startSelf(context);
}
public void setStockTranslations() {
@@ -36,8 +36,6 @@ public class ForegroundDetector implements Application.ActivityLifecycleCallback
@Override
public void onActivityStarted(Activity activity) {
refs++;
activity.stopService(new Intent(activity, KeepAliveService.class));
application.dcContext.startThreads(0);
}
@@ -1,26 +0,0 @@
package org.thoughtcrime.securesms.connect;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ApplicationDcContext dcContext = DcHelper.getContext(context);
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.i("DeltaChat", "-------------------- Screen off --------------------");
dcContext.isScreenOn = false;
KeepAliveService.startSelf(context);
}
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.i("DeltaChat", "-------------------- Screen on --------------------");
dcContext.isScreenOn = true;
context.stopService(new Intent(context, KeepAliveService.class));
}
}
}