private void setForeground() { boolean enable = Preferences.getForegroundServiceEnabled(this); if (enable) { startForeground(NOTIFICATION_ID_FOREGROUND, MessagingNotification.buildForegroundNotification(this)); } else { ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE); } }
public int onStartCommand(Intent intent, int flags, int startId) { // Tell any local interested parties about the start. mLocalBroadcastManager.sendBroadcast(new Intent(ACTION_STARTED)); // Prepare to do update reports. mHandler.removeMessages(MSG_UPDATE); Message msg = mHandler.obtainMessage(MSG_UPDATE); mHandler.sendMessageDelayed(msg, 1000); return ServiceCompat.START_STICKY; }