Swisyn / Android-Consent-SDK-Helper

Android Consent SDK Helper is a library that helps you to integrate and use Google Consent library easily and comply to GDPR.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Consent SDK Helper

Android Consent SDK Helper is a library that helps you to integrate and use Google Consent SDK Android library easily.

You can check the sample for usage of this library.

Video

Android-Consent-SDK-Helper

Usage

Gradle

Add dependency in your app-level build.gradle

implementation 'com.cuneytayyildiz:consent-sdk-helper:1.0.4'

The constructor has 6 parameters, first 3 of them are mandatory.

 class ConsentSDKHelper(
 private val context: Context, // An activity or application context
 private val publisherId: String, // Publisher ID from AdMob, Go to AdMob -> Left Menu -> Settings -> Under the Account information section
 private val privacyPolicyURL: String, // Privacy Policy URL for your app
 private val admobTestDeviceId: String = "", // Check the logcat to get a test device id 
 private var DEBUG: Boolean = false, // You can use BuildConfig.DEBUG to test consent dialog
 private var isEEA: Boolean = false // To check how consent library acts if user within EU region or not.
 )

Implementation

Simply call the checkConsent()

ConsentSDKHelper(this, publisherId, policyURL).checkConsent()

or

 val consentSDK = ConsentSDKHelper(this, publisherId, policyURL)
        consentSDK.checkConsent(object : ConsentCallback {
            override fun onResult(isRequestLocationInEeaOrUnknown: Boolean) {
                // do something with the result
            }
        })

To generate ad requests

After you have implemented this library, you should use something like below to create new ad requests. The function has 3 parameters including 2 optionals to get test ads.

 private val adRequest: AdRequest
        get() {
            return when (BuildConfig.DEBUG) {
                true -> AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice(adsTestDeviceId)
                    .addNetworkExtrasBundle(
                        AdMobAdapter::class.java,
                        ConsentSDKHelper.getNetworkExtrasBundle(this@MainActivity)
                    )
                    .build()
                false -> AdRequest.Builder()
                    .addNetworkExtrasBundle(
                        AdMobAdapter::class.java,
                        ConsentSDKHelper.getNetworkExtrasBundle(this@MainActivity)
                    )
                    .build()
            }
        }
    // load a banner ad
    adView.loadAd(adRequest);
    // load a Interstitial ad
    interstitialAd.loadAd(adRequest);

Change or revoke consent

There is also a preference, to allow users to update their consent just like the Google App.

I have translated all the languages spoken in European Region, all pull requests are welcome to make translations clear.:heart:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.cuneytayyildiz.android.consent.sdk.helper.preference.ConsentSDKHelperPreference
        android:key="preference_ad_choice"
        app:csdk_privacy_policy_url="@string/admob_publisher_id"
        app:csdk_publisher_id="@string/privacy_policy_url" />

</android.support.v7.preference.PreferenceScreen>

Publisher ID and Privacy Policy URL attributes must not be empty

   <declare-styleable name="ConsentSDKHelperPreference">
        <attr name="csdk_publisher_id" format="string" />
        <attr name="csdk_privacy_policy_url" format="string"/>
        <attr name="csdk_title_size" format="dimension"/>
    </declare-styleable>

License

MIT License

Copyright (c) 2018 Cüneyt AYYILDIZ

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


More details:

Requesting Consent from European Users

About

Android Consent SDK Helper is a library that helps you to integrate and use Google Consent library easily and comply to GDPR.

License:MIT License


Languages

Language:Kotlin 100.0%