Files
darkfi/bin/app/java/ForegroundService.java
2026-01-01 11:40:45 +00:00

77 lines
2.4 KiB
Java

/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2026 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package TARGET_PACKAGE_NAME;
import android.app.Service;
import android.content.pm.ServiceInfo;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
public class ForegroundService extends Service {
@Override
public void onCreate() {
super.onCreate();
createNotificationChannel();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//Log.d("darkfi", "ForegroundService::onStartCommand()");
Notification.Builder builder =
new Notification.Builder(this, "darkfi_service");
Notification notification = builder
.setContentTitle("DarkFi")
.setContentText("Running p2p network...")
.setSmallIcon(android.R.drawable.ic_dialog_info)
.build();
startForeground(
100,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
);
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void createNotificationChannel() {
//Log.d("darkfi", "ForegroundService::createNotificationChannel()");
NotificationChannel channel = new NotificationChannel(
"darkfi_service",
"DarkFi Foreground Service",
NotificationManager.IMPORTANCE_DEFAULT
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}