Foreground service and associated notification on Android. Not sure about this as the notification is never shown on the emulator.

This commit is contained in:
Pierrot 2019-04-29 09:57:49 +02:00
parent 56c94afa27
commit fcadc31f4c
3 changed files with 40 additions and 0 deletions

View file

@ -3,5 +3,6 @@
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
</manifest>

View file

@ -2,6 +2,10 @@ package net.pierrox.lightning_launcher.overlay;
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
@ -56,6 +60,9 @@ public class WindowService extends Service implements LightningEngine.GlobalConf
private static final int OPEN_CLOSE_ANIMATION_DURATION = 300;
private static final String NOTIFICATION_CHANNEL_ID = "LL_SERVICES";
private static final int NOTIFICATION_ID = 0;
private WindowScreen mScreen;
private ResourcesWrapperHelper mResourcesWrapperHelper;
@ -332,12 +339,43 @@ public class WindowService extends Service implements LightningEngine.GlobalConf
configureScreen();
configureDrawer();
if (Build.VERSION.SDK_INT >= 26) {
CharSequence name = "Lightning Services";
String description = "Background Launcher activities";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
Intent notificationIntent = LLApp.get().getWindowServiceIntent();
notificationIntent.setAction(WindowService.INTENT_ACTION_SHOW);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, notificationIntent, 0);
Notification.Builder builder;
if (Build.VERSION.SDK_INT >= 26) {
builder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID);
} else {
builder = new Notification.Builder(this);
}
builder.setContentTitle(getString(R.string.ov_r))
.setContentIntent(pendingIntent)
.setCategory(Notification.CATEGORY_SERVICE)
.setPriority(Notification.PRIORITY_LOW);
Notification notification = builder.build();
startForeground(NOTIFICATION_ID, notification);
}
@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
final LLApp app = LLApp.get();
app.getAppEngine().unregisterGlobalConfigChangeListener(this);

View file

@ -1222,6 +1222,7 @@
<string name="an_ohs">Open the hierarchy screen</string>
<string name="ov_pt">Setup</string>
<string name="ov_ps">The overlay desktop requires the permission to draw over other apps</string>
<string name="ov_r">The overlay desktop is enabled</string>
<string name="ism_t">Size mode</string>
<string-array name="ism_e">
<item>Standard</item>