How to create a Custom MoPub GDPR Consent Dialog in Android using Kotlin
- September 07, 2019
- John Codeos
To create a MoPub account, follow the tutorial: How to Create an Account on MoPub
In this tutorial, I will show you how to create a custom GDPR consent dialog for MoPub using Kotlin by adding our own Activity with text and colors.
MoPub offers its own consent dialog to use when you set up their SDK in your app.
This gives us a very limited customization, and in most cases, the colors and the feeling don’t fit in our app design and make users suspicious and rate our app negatively, or delete our app completely from their device.
So, to fix that, it’s good to make our GPDR consent dialog as friendly as possible and make the users understand what’s going on in this situation.
Suppose we have MoPub already installed in our project, so let’s make our own dialog.
If you don’t have MoPub on your Android app yet, check out the tutorial: How to add MoPub Ads in your Android app using Kotlin
Adding Custom GDPR Consent Dialog
First, let’s create our Activity by right-clicking on our package name folder and go to New>Activity>Empty Activity
..and give it the name CustomConsentDialog and press Finish.
Next, go to the activity_custom_consent_dialog.xml file under the layout folder and paste:
Now go to the CustomConsentDialog.kt file and paste:
Adding the Text
In this example, I created a Kotlin class named Constant, so we can organize the texts for our consent dialog:
Of course, you can change it in your text, that’s why we created a Custom GDPR Consent Dialog.
Now just go to your file where MoPub was calling to show the default dialog before, in our example MyMoPub.kt, and add our Activity we created(CustomConsentDialog):
..and run it!
You can find the final project here
If you have any questions feel free to DM me on Twitter @johncodeos or leave a comment below!