{"id":23173564,"url":"https://github.com/smartlook/android-consent-sdk","last_synced_at":"2025-08-18T09:30:35.527Z","repository":{"id":37706952,"uuid":"170863443","full_name":"smartlook/android-consent-sdk","owner":"smartlook","description":"Configurable consent SDK for Android","archived":false,"fork":false,"pushed_at":"2024-05-21T12:00:58.000Z","size":1178,"stargazers_count":84,"open_issues_count":2,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T01:51:14.331Z","etag":null,"topics":["android","consent","google","sdk","sdk-android"],"latest_commit_sha":null,"homepage":"https://www.smartlook.com","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartlook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-15T12:43:26.000Z","updated_at":"2025-02-19T12:08:43.000Z","dependencies_parsed_at":"2022-09-15T22:40:33.086Z","dependency_job_id":null,"html_url":"https://github.com/smartlook/android-consent-sdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/smartlook/android-consent-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartlook%2Fandroid-consent-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartlook%2Fandroid-consent-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartlook%2Fandroid-consent-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartlook%2Fandroid-consent-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartlook","download_url":"https://codeload.github.com/smartlook/android-consent-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartlook%2Fandroid-consent-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270972988,"owners_count":24678001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","consent","google","sdk","sdk-android"],"created_at":"2024-12-18T05:16:30.713Z","updated_at":"2025-08-18T09:30:34.967Z","avatar_url":"https://github.com/smartlook.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consent SDK for Android\n\nObtaining explicit user consent regarding the gathering analytics data in an app, or with processing user’s personal data is an important part of establishing user trust and seamless user experience.\n\nAlthough implementing some form to obtain user consents and store them for further reference seems pretty straightforward, digging into it reveals (as usual with “simple tasks”) many programming and design details that must be implemented, which are not the core functionality of your app.\n\n\u003cimg src=\"screenshots/consent_form_activity.png\" width=\"300\"/\u003e \u003cimg src=\"screenshots/consent_form_dialog.png\" width=\"300\"/\u003e \n\n## Consent SDK main functionality\n\n- Provides configurable __consent form__ that can be displayed as:\n  - __Dialog__\n  - __FragmentDialog__(persists orientation changes)\n  - __Activity__\n  - __Fragment__\n- Stores consent results and provides access methods.\n\n## Installation\nAdd the following dependency in your app's build.gradle:\n\n```\nimplementation 'com.smartlook:consent:1.0'\n```\n\nAnd add the following in your project's build.gradle:\n\n```\nallprojects {\n    repositories {\n        maven {\n            url \"https://sdk.smartlook.com/android/release\"\n        }\n    }\n}\n```\n\n## How to use\n\nFirstly you need to instantiate `ConsentSDK` with `applicationContext`.\n\n```\nval consentSDK = ConsentSDK(applicationContext)\n```\n\nThis object is going to be used for all interactions with ConsentSDK.\n\n### Consent form data\n\nBefore you can display consent form you need to prepare consent form data.\n\n```\ncompanion object {\n    const val CONSENT_1_KEY = \"consent_1_key\"\n    const val CONSENT_2_KEY = \"consent_2_key\"\n}\n\n...\n\nval consentFormItems = arrayOf(\n    ConsentFormItem(\n        consentKey = CONSENT_1_KEY,\n        required = true,\n        description = getString(R.string.consent_1_description),\n        link = null\n    ),\n    ConsentFormItem(\n        consentKey = CONSENT_2_KEY,\n        required = false,\n        description = getString(R.string.consent_2_description),\n        link = getString(R.string.consent_2_link)\n    )\n)\n\nval consentFormData = ConsentFormData(\n    titleText = getString(R.string.consent_form_title),\n    descriptionText = getString(R.string.consent_form_description),\n    confirmButtonText = getString(R.string.consent_form_confirm_button_text),\n    consentFormItems = consentFormItems)\n\n```\n\nArray `consentFormItems` represents consents we want the user to grant us. Every item needs to have:\n - unique `consentKey` that represents it and can be used to obtain grant result for this consent.\n - `required` flag. If this flag is set to `true` user cannot successfully finish the consent form without granting this consent.\n - `descriptionText` informing the user about the consent.\n - `link` (optional) that lets the user open a web page (URL) with more info.\n \n Object `consentFormData` provides all needed data for displaying consent form.\n\n### Showing consent form on `Dialog`\nA most simple and straight-forward way of displaying consent form is on `Dialog`. It has one __drawback__, this way we __cannot__ properly persist user data on orientation change. Use this if you have locked screen orientation.\n\n```\nconsentSDK.showConsentFormDialog(consentFormData, object : ConsentResultsListener {\n    override fun onConsentResults(consentResults: HashMap\u003cString, Boolean\u003e) {\n        // consent form result here\n    }\n})\n```\n\n### Showing consent form on `DialogFragment`\nBy using `DialogFragment` SDK can properly handle orientation changes.\n\n```\nconsentSDK.showConsentFormDialogFragment(\u003cactivity\u003e/\u003cfragment\u003e, consentFormData)\n```\n\nThe first parameter of `showConsentFormDialogFragment` accepts `Activity` or `Fragment` reference so you can call it from both.\nYour calling `Activity` or `Fragment` __must__ implement ConsentResultsListener.\n\n```\nclass SampleActivity : AppCompatActivity(), ConsentResultsListener {\n\n...\n\n  override fun onConsentResults(consentResults: HashMap\u003cString, Boolean\u003e) {\n      // consent form result here\n  }\n}\n```\n\n### Starting consent form `Activity`\n\n```\nclass SampleActivity : AppCompatActivity() {\n\n  companion object {\n      const val CONSENT_REQUEST_CODE = 10001\n  }\n\n  ...\n\n  consentSDK.startConsentFormActivity(this, consentFormData, CONSENT_REQUEST_CODE)\n\n  ...\n\n  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n      if (requestCode == CONSENT_REQUEST_CODE) {\n          if (resultCode == Activity.RESULT_OK) {\n              val consentResults = consentSDK.parseOutConsentResults(data)\n          } else {\n              // user didnt confirm the form (back press)\n          }\n      }\n  }\n}\n```\n\nConsent form `Activity` is started \"for a result\" so to get a result you need to implement `onActivityResult` method in your `Activity`. \n\n### Creating conset form `Fragment`\nMethod `createConsentFormFragment` lets you create `Fragment` with consent form. Example usage might look something like this:\n\n```\nconst val TAG = \"unique_fragment_tag\"\n\n...\n\nwith(supportFragmentManager) {\n    beginTransaction()\n        .replace(R.id.fragment_placeholder, consentSDK.createConsentFormFragment(consentFormData), TAG)\n        .commit()\n    executePendingTransactions()\n}\n```\n\n`ConsentResultsListener` can be registered like this:\n\n```\nval consentFormFragment = supportFragmentManager.findFragmentByTag(TAG) as ConsentFormFragment\nconsentFormFragment.registerConsentResultsListener(object : ConsentResultsListener {\n            override fun onConsentResults(consentResults: HashMap\u003cString, Boolean\u003e) {\n                // Consent form result here\n            }\n        })\n```\n\n### Consent results\nWhen user sucessfully finishes consent form you gonna get `consentResult`. It is a `HashMap\u003cString,Boolean\u003e` in which:\n- `key` == `consentKey`\n- `value` represents `consentResult`:\n  - `true` consent was granted.\n  - `false` consent was rejected.\n\n### Are consent results stored?\nSDK method `areConsentResultsStored()` can be used to determine if the user has already successfully filled consent form and results were stored.\n\n### Obtaining consent\n\nIf you want to obtain a grant result for given conset (identified by unique `consentKey`) you can do it like this:\n\n```\nval consentResult = consentSDK.loadConsetResult(consentKey)\n```\n\nIf `consentResult` is:\n- `true` consent was granted.\n- `false` consent was rejected.\n- `null` not defined.\n\n## Styling\n\n\u003cimg src=\"screenshots/consent_form_activity_styled.png\" width=\"300\"/\u003e \u003cimg src=\"screenshots/consent_form_dialog_styled.png\" width=\"300\"/\u003e \n\nYou can define custom `style` for the consent form. All configurable attributes are listed in the table below.\n\n|         Attribute         |                    Description                   |\n|:-------------------------:|:------------------------------------------------:|\n| colorAccent               | Confirm button, link icons and `Switches` color. |\n| cf_textColor              | Description text and form item texts color.      |\n| cf_titleTextColor         | Title text color.                                |\n| cf_confirmButtonTextColor | Confirm button text color.                       |\n| cf_backgroundColor        | Form background color.                           |\n| cf_dividerColor           | Form item list divider color.                    |\n\n### `Dialog`/`FragmentDialog` \n\nIn `styles.xml` define custom Dialog style:\n\n```\n\u003cstyle name=\"DialogStyle\" parent=\"Base.Theme.AppCompat.Light.Dialog\"\u003e\n    \u003citem name=\"colorAccent\"\u003e#35E6A5\u003c/item\u003e\n    \u003citem name=\"cf_textColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_titleTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_confirmButtonTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_backgroundColor\"\u003e#26262E\u003c/item\u003e\n    \u003citem name=\"cf_dividerColor\"\u003e#F4F4F4\u003c/item\u003e\n\u003c/style\u003e\n```\n\nThen add the style reference to `showConsentFormDialog`/`showConsentFormDialogFragment` method like this:\n\n```\n// Dialog\nconsentSDK.showConsentFormDialog(this, consentFormData, R.style.DialogStyle, listener)\n\n// DialogFragment\nconsentSDK.showConsentFormDialogFragment(this, consentFormData, R.style.DialogStyle)\n```\n\n### `Activity`\n\nIn `styles.xml` define custom Activity style:\n\n```\n\u003cstyle name=\"ActivityStyle\" parent=\"Theme.AppCompat.Light.NoActionBar\"\u003e\n    \u003citem name=\"colorAccent\"\u003e#21A76A\u003c/item\u003e\n    \u003citem name=\"cf_textColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_titleTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_confirmButtonTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_backgroundColor\"\u003e#26262E\u003c/item\u003e\n    \u003citem name=\"cf_dividerColor\"\u003e#F4F4F4\u003c/item\u003e\n\u003c/style\u003e\n```\n\nThen add the style reference to `startConsentFormActivity` method like this:\n\n```\nconsentSDK.startConsentFormActivity(this, consentFormData, CONSENT_REQUEST_CODE, R.style.ActivityStyle)\n```\n\n### Fragment\n\nIn `styles.xml` define custom Fragment style:\n\n```\n\u003cstyle name=\"FragmentStyle\" parent=\"Theme.AppCompat.Light.NoActionBar\"\u003e\n    \u003citem name=\"colorAccent\"\u003e#21A76A\u003c/item\u003e\n    \u003citem name=\"cf_textColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_titleTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_confirmButtonTextColor\"\u003e#F4F4F4\u003c/item\u003e\n    \u003citem name=\"cf_backgroundColor\"\u003e#26262E\u003c/item\u003e\n    \u003citem name=\"cf_dividerColor\"\u003e#F4F4F4\u003c/item\u003e\n\u003c/style\u003e\n```\n\nThen add the style reference to `startConsentFormActivity` method like this:\n\n```\nconsentSDK.createConsentFormFragment(consentFormData, R.style.FragmentStyle)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartlook%2Fandroid-consent-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartlook%2Fandroid-consent-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartlook%2Fandroid-consent-sdk/lists"}