将 GDPR 添加到 Android Studio
Posted
技术标签:
【中文标题】将 GDPR 添加到 Android Studio【英文标题】:Adding GDPR to Android Studio 【发布时间】:2018-11-20 05:03:45 【问题描述】:为什么没有显示 GDPR 表单?
我把这个放在build.gradle
:
allprojects
repositories
jcenter()
maven
url "https://maven.google.com"
implementation 'com.google.android.ads.consent:consent-library:1.0.3'
这主要是:
import android.util.Log;
import com.google.ads.consent.*;
import java.net.MalformedURLException;
import java.net.URL;
ConsentForm form;
private static final String TAG = "MainActivity ----- : " ;
ConsentInformation consentInformation = ConsentInformation.getInstance(MainActivity.this);
String[] publisherIds = "pub-9138443983781653";
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener()
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus)
// User's consent status successfully updated.
Log.d(TAG,"onConsentInfoUpdated");
switch (consentStatus)
case PERSONALIZED:
Log.d(TAG,"PERSONALIZED");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
break;
case NON_PERSONALIZED:
Log.d(TAG,"NON_PERSONALIZED");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
break;
case UNKNOWN:
Log.d(TAG,"UNKNOWN");
if(ConsentInformation.getInstance(MainActivity.this).isRequestLocationInEeaOrUnknown())
URL privacyUrl = null;
try
// TODO: Replace with your app's privacy policy URL.
privacyUrl = new URL("https://www.appprivacy.com/privacyurl");
catch (MalformedURLException e)
e.printStackTrace();
// Handle error.
form = new ConsentForm.Builder(MainActivity.this, privacyUrl)
.withListener(new ConsentFormListener()
@Override
public void onConsentFormLoaded()
// Consent form loaded successfully.
Log.d(TAG,"onConsentFormLoaded");
showform();
@Override
public void onConsentFormOpened()
// Consent form was displayed.
Log.d(TAG,"onConsentFormOpened");
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree)
// Consent form was closed.
Log.d(TAG,"onConsentFormClosed");
@Override
public void onConsentFormError(String errorDescription)
// Consent form error.
Log.d(TAG,"onConsentFormError");
Log.d(TAG,errorDescription);
)
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.build();
form.load();
else
Log.d(TAG,"PERSONALIZED else");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
break;
default:
break;
@Override
public void onFailedToUpdateConsentInfo(String errorDescription)
// User's consent status failed to update.
Log.d(TAG,"onFailedToUpdateConsentInfo");
Log.d(TAG,errorDescription);
);
private void showform()
if (form!=null)
Log.d(TAG,"show ok");
form.show();
调试应用时发现应用没有进入:
@覆盖 公共无效 onConsentInfoUpdated(ConsentStatus 同意状态)
代码有问题吗?如果我们想更新一个旧的应用程序 我们应该只添加这样的简单代码还是更改每个单元?
【问题讨论】:
我在许可 sdk 上制作了视频,请看这里youtube.com/watch?v=_JOapnq8hrs&t=768s 【参考方案1】:添加这个:
ConsentInformation.getInstance(MainActivity.this).setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
【讨论】:
以上是关于将 GDPR 添加到 Android Studio的主要内容,如果未能解决你的问题,请参考以下文章
如何将 iPhone 添加到 Android Studio?
将 JSON 数据添加到 Android Studio 地图
如何将 Android Studio 项目添加到 GitHub [重复]