/// <summary>
        /// When using the MAM-WE APIs found in IMAMEnrollManager, your app wil receive
        /// IMAMEnrollmentNotifications back to signal the result of your calls.
        ///
        /// More information can be found here: https://docs.microsoft.com/en-us/intune/app-sdk-android#result-and-status-codes
        /// </summary>
        public bool OnReceive(IMAMNotification notification)
        {
            if (notification.Type != MAMNotificationType.MamEnrollmentResult)
            {
                return(true);
            }

            IMAMEnrollmentNotification enrollmentNotification = notification.JavaCast <IMAMEnrollmentNotification>();
            MAMEnrollmentManagerResult result = enrollmentNotification.EnrollmentResult;
            string upn = enrollmentNotification.UserIdentity;

            string message = string.Format(
                "Received MAM Enrollment result {0} for user {1}.", result.Name(), upn);

            Log.Info(GetType().Name, message);

            Handler handler = new Handler(context.MainLooper);

            handler.Post(() => { Toast.MakeText(context, message, ToastLength.Long).Show(); });

            if (result.Equals(MAMEnrollmentManagerResult.EnrollmentSucceeded) ||
                result.Equals(MAMEnrollmentManagerResult.NotLicensed) ||
                result.Equals(MAMEnrollmentManagerResult.Pending) ||
                result.Equals(MAMEnrollmentManagerResult.UnenrollmentFailed) ||
                result.Equals(MAMEnrollmentManagerResult.UnenrollmentSucceeded))
            {
                // You are not required to do anything here, these are primarily informational callbacks
                // so you can know the state of the enrollment attempt.
            }
            else if (result.Equals(MAMEnrollmentManagerResult.AuthorizationNeeded))
            {
                // Attempt to re-authorize.
                Authenticator.GetAuthenticator().UpdateAccessTokenForMAM();
            }
            else if (result.Equals(MAMEnrollmentManagerResult.CompanyPortalRequired))
            {
                // Intune blocks the user until the Company Portal is installed on the device.
                // An app can override OnMAMCompanyPortalRequired in a MAMActivity to add custom handling to this behavior.
            }
            else if (result.Equals(MAMEnrollmentManagerResult.EnrollmentFailed) ||
                     result.Equals(MAMEnrollmentManagerResult.WrongUser))
            {
                string blockMessage = Application.Context.GetString(Resource.String.err_blocked, result.Name());
                BlockUser(handler, blockMessage);
            }
            else
            {
                throw new NotSupportedException(string.Format("Unknown result code: {0}", result.Name()));
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// When using the MAM-WE APIs found in IMAMEnrollManager, your app wil receive
        /// IMAMEnrollmentNotifications back to signal the result of your calls.
        /// When enrollment is successful, this will signal that app has been registered and it can proceed ahead.
        /// </summary>
        /// <param name="notification">The notification that was received.</param>
        /// <returns>
        /// The receiver should return true if it handled the notification without error(or if it decided to ignore the notification).
        /// If the receiver tried to take some action in response to the notification but failed to complete that action it should return false.
        /// </returns>
        public bool OnReceive(IMAMNotification notification)
        {
            if (notification.Type == MAMNotificationType.MamEnrollmentResult)
            {
                IMAMEnrollmentNotification enrollmentNotification = notification.JavaCast <IMAMEnrollmentNotification>();
                MAMEnrollmentManagerResult result = enrollmentNotification.EnrollmentResult;

                if (result.Equals(MAMEnrollmentManagerResult.EnrollmentSucceeded))
                {
                    // this signals that MAM registration is complete and the app can proceed
                    IntuneSampleApp.MAMRegsiteredEvent.Set();
                }
            }

            return(true);
        }