package com.communal_app; import com.facebook.react.ReactActivity; import org.devio.rn.splashscreen.SplashScreen; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; import android.graphics.Color; import android.os.Handler; import android.os.Message; import com.rnheartbeat.HeartbeatService; import android.content.Context; import android.content.Intent; import com.log.L; import com.wix.reactnativenotifications.core.notification.IPushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification; public class MainActivity extends ReactActivity { /** * Returns the name of the main component registered from JavaScript. * This is used to schedule rendering of the component. */ @Override protected String getMainComponentName() { return "communal_app"; } @Override protected void onCreate(Bundle savedInstanceState) { L.v("MainActivity.onCreate()"); Context context = this; SplashScreen.show(this); splashScreenHideHandler.sendEmptyMessageDelayed(1, 10000); // needed in dev mode when dev server is not set up first time and default React Native app comes in - there is no call to js's SplashScreen.hide() in App.js setStatusBar(); handleNotification(); context.startService(new Intent(context, HeartbeatService.class)); super.onCreate(savedInstanceState); } // https://github.com/wix/react-native-notifications/issues/326#issuecomment-507371366 private void handleNotification() { Bundle notificationData = getIntent().getExtras(); if (notificationData != null) { final IPushNotification notification = PushNotification.get(getApplicationContext(), notificationData); if (notification != null) { notification.onOpened(); } } } // https://github.com/invertase/react-native-firebase/issues/1331 @Override public void onNewIntent(Intent intent) { setIntent(intent); super.onNewIntent(intent); } // https://stackoverflow.com/questions/11708450/java-timer-in-android private Handler splashScreenHideHandler = new Handler() { @Override public void handleMessage(Message msg) { SplashScreen.hide(MainActivity.this); } }; private void setStatusBar() { Window window = getWindow(); // clear FLAG_TRANSLUCENT_STATUS flag: window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // finally change the color // window.setStatusBarColor(ContextCompat.getColor(this, R.color.my_statusbar_color)); window.setStatusBarColor(Color.parseColor("#FFFFFF")); } }