Commonly used set of ad technology providers use a custom dialog (GDPR) - nouhcc/GDPR_Example GitHub Wiki

GDPR Implementation

Project Android for GDPR, implement The GDPR Admob dialog to ask EU users if they want to give their data to show relevant ads, (two choices are possible). Yes, let Admob pick data to show the best and interesting ads for users.
No, show no relevant ads (low CPC & CPM). Notice : This is a custom GDPR with all ADmob providers not only 12.

Step 1. Add in your root build.gradle at the end of repositories:

allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

Step 2. Add the dependency

dependencies { implementation 'com.github.nouhcc:GDRPLib:1.0.2' }

3. add this piece of code and change what you have to change

`

private GDPRLib custom;

`

4. in the onCreate() methode :

custom = new GDPRLib.Builder(this) .addCallBack(this) callBack to determine what to do after the dialog has ended .addLayoutInflater(getLayoutInflater()) // the layout that should be use for the dialog .addPrivacyPolicy("http://your.policy.com/Policy.html") //your own privacy policy .addPublisherId("pub-2307105849827608") // publisher id from Admob .build(); custom.checkConsentStatus(this);

5. for the callback you must either implement your class with Consent_callback and then use OnDialogClose() method

`

public class ActivitySplash extends AppCompatActivity implements Consent_callback {

    private GDPRLib custom;

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            custom = new GDPRLib.Builder(this)
                    .addCallBack(this) //callBack to determine what to do after the dialog has ended
                    .addLayoutInflater(getLayoutInflater()) // the layout that should be use for the dialog
                    .addPrivacyPolicy("http://your.policy.com/Policy.html") //your own privacy policy
                    .addPublisherId("pub-2307105849827608") // publisher id from Admob
                    .build();
            custom.checkConsentStatus(this);
    }

`

add this :

`

@Override public void OnDialogClose() { startNextActivity(); }

`

or directly when initialisation GDRPLib :

`

        custom = new GDPRLib.Builder(this)
                    .addCallBack(new Consent_callback() {
                            @Override
                            public void OnDialogClose() {
                                    // your code here
                            }
                    }) //callBack to determine what to do after the dialog has ended
                    .addLayoutInflater(getLayoutInflater()) // the layout that should be use for the dialog
                    .addPrivacyPolicy("http://your.policy.com/Policy.html") //your own privacy policy
                    .addPublisherId("pub-233333849827608") // publisher id from Admob
                    .build();
            custom.checkConsentStatus(this);

`

6. you can change the colors by adding the in your color.xml

`

// this colors are for your dialog #ff5b1d

<color name="lonodev_colorTextButton1">#ffffff</color>

<color name="lonodev_colorButton2">#644c43</color>

<color name="lonodev_colorTextButton2">#ffffff</color>

<color name="lonodev_colorHeader">#ff5b1d</color>

<color name="lonodev_colorText1">#042f51</color>

<color name="lonodev_colorText2">#0489f5</color>

<color name="lonodev_colorText3">#e9181c</color>

<color name="lonodev_colorText4">#0078d9</color>

`

7. You can modify the style of the button in your styles.xml :

`

<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/lonodev_colorButton1</item>
    <item name="android:textColor">@color/lonodev_colorTextButton1</item>
</style>
<style name="AppTheme.Button2" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/lonodev_colorButton2</item>
    <item name="android:textColor">@color/lonodev_colorTextButton2</item>
</style>

`

8. you can change the text or add a new translated ( the dialog is translated by default to only 3 languages Fr,Ar,Uk) by adding in your strings.xml :

`

<string name="eu_consent_text">Dear user!\n\nWe use Google Admob to show ads. Ads support our work, and enable further development of this app. In line with the new European Data Protection Regulation (GDPR), we need your consent to serve ads tailored for you.</string>
<string name="eu_consent_question">Can your data be used to show ads tailored for you?</string>
<string name="eu_learn_more">Learn how your data is used</string>
<string name="eu_google_partners">Google and its partners:</string>
<string name="eu_consent_yes">Yes, continue to show relevant ads</string>
<string name="eu_consent_no">No, show ads that are irrelevant</string>
<string name="eu_consent_change_setting">You can change this setting anytime in the \"About\" window.</string>
<string name="eu_thank_you">Thank you!</string>
<string name="eu_privacy_policy" >Privacy Policies </string>
<string name="eu_dialog_close" >close</string>
<string name="eu_Text2_learn_more">" Policies for"</string>
<string name="eu_Text3_learn_more">Terms and Policies of Providers</string>

`

  1. you can change the default logo in the dialog :

` custom = new GDPRLib.Builder(this) .addCallBack(this) .addLayoutInflater(getLayoutInflater()) .addPrivacyPolicy("http://your.policy.com/Policy.html") .addPublisherId("pub-23333339827608") .addDrowableId(R.drawable.ic_launcher_background) //change the drawable on top of the dialog .build();

` ##SCREENSHOTS

⚠️ **GitHub.com Fallback** ⚠️