| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Notification; |
| 4 | import android.app.NotificationChannel; |
| 5 | import android.app.NotificationManager; |
| 6 | import android.app.PendingIntent; |
| 7 | import android.app.Service; |
| 8 | import android.content.Context; |
| 9 | import android.content.Intent; |
| 10 | import android.os.Build; |
| 11 | import android.os.IBinder; |
| 12 | |
| 13 | import org.telegram.messenger.ApplicationLoader; |
| 14 | import org.telegram.messenger.LocaleController; |
| 15 | import org.telegram.messenger.R; |
| 16 | import org.telegram.ui.LaunchActivity; |
| 17 | |
| 18 | public class DuangService extends Service { |
| 19 | |
| 20 | NotificationManager systemNotificationManager = null; |
| 21 | |
| 22 | @Override |
| 23 | public IBinder onBind(Intent intent) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 29 | Intent activityIntent = new Intent(this, LaunchActivity.class); |
| 30 | PendingIntent pendingIntent = PendingIntent.getActivity(getApplication(), 0, activityIntent, 0); |
| 31 | |
| 32 | Notification.Builder builder; |
| 33 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { |
| 34 | NotificationChannel notificationChannel = new NotificationChannel("duang", "Other", NotificationManager.IMPORTANCE_DEFAULT); |
| 35 | notificationChannel.enableLights(false); |
| 36 | notificationChannel.enableVibration(false); |
| 37 | notificationChannel.setSound(null, null); |
| 38 | systemNotificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 39 | systemNotificationManager.createNotificationChannel(notificationChannel); |
| 40 | builder = new Notification.Builder(getApplication(), "duang"); |
| 41 | } else { |
| 42 | builder = new Notification.Builder(getApplication()); |
| 43 | |
| 44 | } |
| 45 | Notification notification = builder.setSmallIcon(R.drawable.notification). |
| 46 | setContentTitle(LocaleController.getString("NekogramRunning", R.string.NekogramRunning)). |
| 47 | setContentIntent(pendingIntent). |
| 48 | setWhen(System.currentTimeMillis()). |
| 49 | build(); |
| 50 | startForeground(38264, notification); |
| 51 | return super.onStartCommand(intent, flags, startId); |
| 52 | } |
| 53 | } |
| 54 | |