NekoX/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsService.java

82 lines
3.1 KiB
Java
Raw Normal View History

/*
* This is the source code of Telegram for Android v. 1.3.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
*/
2015-09-24 22:52:02 +02:00
package org.telegram.messenger;
2020-02-25 10:04:26 +01:00
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
2020-02-25 10:04:26 +01:00
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
2020-02-25 10:04:26 +01:00
import android.os.Build;
import android.os.IBinder;
2020-06-25 17:28:24 +02:00
import android.provider.Settings;
2020-02-25 10:04:26 +01:00
import androidx.core.app.NotificationCompat;
public class NotificationsService extends Service {
@Override
public void onCreate() {
2019-09-10 12:56:11 +02:00
super.onCreate();
ApplicationLoader.postInitApplication();
2020-06-25 17:28:24 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String CHANNEL_ID = "push_service_channel";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, LocaleController.getString("PlaceHolder", R.string.PlaceHolder), NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("NekoX - System");
channel.enableLights(false);
channel.enableVibration(false);
channel.setSound(null, null);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
2020-02-25 10:04:26 +01:00
}
2020-06-25 17:28:24 +02:00
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, CHANNEL_ID);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
2020-02-25 10:04:26 +01:00
.setSmallIcon(R.drawable.notification)
.setColor(0xff11acfa)
.setContentTitle(LocaleController.getString("NekogramRunning", R.string.NekogramRunning))
2020-06-25 17:28:24 +02:00
.setContentText(LocaleController.getString("TapToDisable",R.string.TapToDisable))
2020-02-25 10:04:26 +01:00
.setContentIntent(pendingIntent)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.build();
startForeground(38264, notification);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void onDestroy() {
2019-09-10 12:56:11 +02:00
super.onDestroy();
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
if (preferences.getBoolean("pushService", true)) {
Intent intent = new Intent("org.telegram.start");
2020-06-25 17:28:24 +02:00
try {
sendBroadcast(intent);
} catch (Exception ex) {
// 辣鷄miui 就你事最多.jpg
}
}
}
2020-06-25 17:28:24 +02:00
}