package org.mercury_im.messenger; import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.os.Build; import org.mercury_im.messenger.di.component.AppComponent; import org.mercury_im.messenger.di.component.DaggerAppComponent; import org.mercury_im.messenger.di.module.AppModule; import org.mercury_im.messenger.di.module.RepositoryModule; import org.mercury_im.messenger.di.module.RoomModule; import org.mercury_im.messenger.service.XmppConnectionService; public class MercuryImApplication extends Application { public static final String TAG = "Mercury-IM"; private static MercuryImApplication INSTANCE; AppComponent appComponent; public static MercuryImApplication getApplication() { return INSTANCE; } @Override public void onCreate() { super.onCreate(); INSTANCE = this; appComponent = DaggerAppComponent.builder() .appModule(new AppModule(this)) .roomModule(new RoomModule(this)) .repositoryModule(new RepositoryModule()) .build(); appComponent.inject(this); initializeNotificationChannels(this); Intent serviceIntent = new Intent(getApplicationContext(), XmppConnectionService.class); serviceIntent.setAction(XmppConnectionService.ACTION_START); if (Build.VERSION.SDK_INT < 26) { startService(serviceIntent); } else { startForegroundService(serviceIntent); } } public void initializeNotificationChannels(Context context) { // Only necessary on Android O and upwards. if (Build.VERSION.SDK_INT < 26) { return; } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Foreground notification channel String fName = getResources().getString(R.string.channel_name_foreground); String fDescription = getResources().getString(R.string.channel_description_foreground); NotificationChannel foreground = new NotificationChannel(Notifications.NOTIFICATION_CHANNEL__FOREGROUND_SERVICE, fName, NotificationManager.IMPORTANCE_DEFAULT); foreground.setDescription(fDescription); foreground.setImportance(NotificationManager.IMPORTANCE_MIN); foreground.setShowBadge(false); notificationManager.createNotificationChannel(foreground); } public AppComponent getAppComponent() { return appComponent; } }