In case it's useful, @adamhalperin : In MainActivity.OnCreate, some time after the call to base.OnCreate(bundle); insert this code snippet:
App.LogMessage("DEBUG: MainActivity.OnCreate: Starting consent management flow, via UserMessagingPlatform.");
try
{
ConsentRequestParameters requestParameters = new ConsentRequestParameters
.Builder()
.SetTagForUnderAgeOfConsent(false)
.Build();
IConsentInformation consentInformation = UserMessagingPlatform.GetConsentInformation(this);
consentInformation.RequestConsentInfoUpdate(
this,
requestParameters,
new GoogleUMPConsentUpdateSuccessListener(
() =>
{
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.IsConsentFormAvailable)
{
UserMessagingPlatform.LoadConsentForm(
this,
new GoogleUMPFormLoadSuccessListener((IConsentForm f)=> {
this.googleUMPConsentForm = f;
this.googleUMPConsentInformation = consentInformation;
App.LogMessage("DEBUG: MainActivity.OnCreate: Consent management flow: LoadConsentForm has loaded a form, which will be shown if necessary, once the ViewModel is ready.");
ViewModel.MainViewModel.OnceViewModelInitialised(DisplayAdvertisingConsentFormIfNecessary);
}),
new GoogleUMPFormLoadFailureListener((FormError e)=> {
// Handle the error.
App.LogMessage("ERROR: MainActivity.OnCreate: Consent management flow: failed in LoadConsentForm with error " + e.Message);
}));
}
else
{
App.LogMessage("DEBUG: MainActivity.OnCreate: Consent management flow: RequestConsentInfoUpdate succeeded but no consent form was available.");
}
}),
new GoogleUMPConsentUpdateFailureListener(
(FormError e) =>
{
// Handle the error.
App.LogMessage("ERROR: MainActivity.OnCreate: Consent management flow: failed in RequestConsentInfoUpdate with error " + e.Message);
})
);
}
catch (Exception ex)
{
App.LogMessage("ERROR: MainActivity.OnCreate: Exception thrown during consent management flow: ", ex);
}
Then, in the body of the MainActivity class, you will also need to add these definitions:
private IConsentForm googleUMPConsentForm = null;
private IConsentInformation googleUMPConsentInformation = null;
public void DisplayAdvertisingConsentFormIfNecessary()
{
try
{
if (ViewModel.MainViewModel.Instance.AdvertisingEnabled)
{
if (googleUMPConsentForm != null && googleUMPConsentInformation != null)
{
/* ConsentStatus:
Unknown = 0,
Required = 1,
NotRequired = 2,
Obtained = 3
*/
if (googleUMPConsentInformation.ConsentStatus == 1)
{
App.LogMessage("DEBUG: MainActivity.DisplayAdvertisingConsentFormIfNecessary: Consent form is being displayed.");
DisplayAdvertisingConsentForm();
}
else
{
App.LogMessage("DEBUG: MainActivity.DisplayAdvertisingConsentFormIfNecessary: Consent form is not being displayed because consent status is "+ googleUMPConsentInformation.ConsentStatus.ToString());
}
}
else
{
App.LogMessage("ERROR: MainActivity.DisplayAdvertisingConsentFormIfNecessary: consent form or consent information missing.");
}
}
}
catch(Exception ex)
{
App.LogMessage("ERROR: MainActivity.DisplayAdvertisingConsentFormIfNecessary: Exception thrown: ", ex);
}
}
public void DisplayAdvertisingConsentForm()
{
try
{
if (ViewModel.MainViewModel.Instance.AdvertisingEnabled)
{
if (googleUMPConsentForm != null && googleUMPConsentInformation != null)
{
App.LogMessage("DEBUG: MainActivity.DisplayAdvertisingConsentForm: Consent form is being displayed.");
Model.DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
googleUMPConsentForm.Show(this, new GoogleUMPConsentFormDismissedListener(
(FormError f) =>
{
if (googleUMPConsentInformation.ConsentStatus == 1) // required
{
App.LogMessage("ERROR: MainActivity.DisplayAdvertisingConsentForm: Consent was dismissed; showing it again because consent is still required.");
Model.DispatcherHelper.RunAsyncOnUI(DisplayAdvertisingConsentForm);
}
}));
});
}
else
{
App.LogMessage("ERROR: MainActivity.DisplayAdvertisingConsentForm: consent form or consent information missing.");
}
}
}
catch (Exception ex)
{
App.LogMessage("ERROR: MainActivity.DisplayAdvertisingConsentForm: Exception thrown: ", ex);
}
}
public class GoogleUMPConsentFormDismissedListener : Java.Lang.Object, IConsentFormOnConsentFormDismissedListener
{
public GoogleUMPConsentFormDismissedListener(Action<FormError> failureAction)
{
this.a = failureAction;
}
public void OnConsentFormDismissed(FormError f)
{
a(f);
}
private Action<FormError> a = null;
}
public class GoogleUMPConsentUpdateFailureListener : Java.Lang.Object, IConsentInformationOnConsentInfoUpdateFailureListener
{
public GoogleUMPConsentUpdateFailureListener(Action<FormError> failureAction)
{
this.a = failureAction;
}
public void OnConsentInfoUpdateFailure(FormError f)
{
a(f);
}
private Action<FormError> a = null;
}
public class GoogleUMPConsentUpdateSuccessListener : Java.Lang.Object, IConsentInformationOnConsentInfoUpdateSuccessListener
{
public GoogleUMPConsentUpdateSuccessListener(Action successAction)
{
this.a = successAction;
}
public void OnConsentInfoUpdateSuccess()
{
a();
}
private Action a = null;
}
public class GoogleUMPFormLoadFailureListener : Java.Lang.Object, UserMessagingPlatform.IOnConsentFormLoadFailureListener
{
public GoogleUMPFormLoadFailureListener(Action<FormError> failureAction)
{
this.a = failureAction;
}
public void OnConsentFormLoadFailure(FormError e)
{
a(e);
}
private Action<FormError> a = null;
}
public class GoogleUMPFormLoadSuccessListener : Java.Lang.Object, UserMessagingPlatform.IOnConsentFormLoadSuccessListener
{
public GoogleUMPFormLoadSuccessListener(Action<IConsentForm> successAction)
{
this.a = successAction;
}
public void OnConsentFormLoadSuccess(IConsentForm f)
{
a(f);
}
private Action<IConsentForm> a = null;
}
This is just a cut-and-paste of my code - in your case you may need to do something different to replace the call to Model.DispatcherHelper.RunAsyncOnUI/Model.DispatcherHelper.CheckBeginInvokeOnUI (which I use to run something on the UI thread), App.LogMessage which I use to write to the app log, and ViewModel.MainViewModel.Instance.AdvertisingEnabled, which is used to check whether the app is meant to display advertising (it will be false if the user paid to remove advertising)