Example #1
0
        private void UpdateForegroundServiceNotificationBuilder()
        {
            AndroidSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper;

            int numRunningStudies = serviceHelper.RunningProtocolIds.Count;

            _foregroundServiceNotificationBuilder.SetContentTitle("You are enrolled in " + numRunningStudies + " " + (numRunningStudies == 1 ? "study" : "studies") + ".");

            string contentText = "";

            // although the number of studies might be greater than 0, the protocols might not yet be started (e.g., after starting sensus).
            List <Protocol> runningProtocols = serviceHelper.GetRunningProtocols();

            if (runningProtocols.Count > 0)
            {
                double avgParticipation = runningProtocols.Average(protocol => protocol.Participation) * 100;
                contentText += "Your overall participation level is " + Math.Round(avgParticipation, 0) + "%. ";
            }

            contentText += "Tap to open Sensus.";

            _foregroundServiceNotificationBuilder.SetContentText(contentText);
        }