- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我尝试使用 Google ConsentSDK 在 Android 应用同意表单中显示。当我调用 form.show() 时出现此错误:“同意书错误同意书尚未准备好显示。”谁能帮帮我?
我的代码:
ConsentForm form = new ConsentForm.Builder(context, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.d("SplashScreen", "Consent form Loaded ");
}
@Override
public void onConsentFormOpened() {
// Consent form was displayed.
Log.d("SplashScreen", "Consent form opened ");
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
Log.d("SplashScreen", "Consent form Closed ");
}
@Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.d("SplashScreen", "Consent form error " + errorDescription);
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.build();
form.load();
form.show();
最佳答案
这是我在我的应用程序中使用的 Google Consent SDK 的帮助程序类。要初始化同意信息并在需要时显示同意书,我在主要 Activity 的 onCreate()
方法中有以下代码:
GdprHelper gdprHelper = new GdprHelper(this);
gdprHelper.initialise();
同样,当用户点击首选项中的“重置我的隐私同意”时,我运行以下代码:
GdprHelper gdprHelper = new GdprHelper(this);
gdprHelper.resetConsent();
这两次都是指当前正在运行的 Activity 。
辅助类的完整实现:
package com.example.app;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;
import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
import com.google.ads.consent.ConsentInfoUpdateListener;
import com.google.ads.consent.ConsentInformation;
import com.google.ads.consent.ConsentStatus;
import java.net.MalformedURLException;
import java.net.URL;
public class GdprHelper {
private static final String PUBLISHER_ID = "YOUR-PUBLISHER-ID";
private static final String PRIVACY_URL = "YOUR-PRIVACY-URL";
private static final String MARKET_URL_PAID_VERSION = "market://details?id=com.example.app.pro";
private final Context context;
private ConsentForm consentForm;
public GdprHelper(Context context) {
this.context = context;
}
// Initialises the consent information and displays consent form if needed
public void initialise() {
ConsentInformation consentInformation = ConsentInformation.getInstance(context);
consentInformation.requestConsentInfoUpdate(new String[]{PUBLISHER_ID}, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
if (consentStatus == ConsentStatus.UNKNOWN) {
displayConsentForm();
}
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// Consent form error. Would be nice to have proper error logging. Happens also when user has no internet connection
if (BuildConfig.BUILD_TYPE.equals("debug")) {
Toast.makeText(context, errorDescription, Toast.LENGTH_LONG).show();
}
}
});
}
// Resets the consent. User will be again displayed the consent form on next call of initialise method
public void resetConsent() {
ConsentInformation consentInformation = ConsentInformation.getInstance(context);
consentInformation.reset();
}
private void displayConsentForm() {
consentForm = new ConsentForm.Builder(context, getPrivacyUrl())
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form has loaded successfully, now show it
consentForm.show();
}
@Override
public void onConsentFormOpened() {
// Consent form was displayed.
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed. This callback method contains all the data about user's selection, that you can use.
if (userPrefersAdFree) {
redirectToPaidVersion();
}
}
@Override
public void onConsentFormError(String errorDescription) {
// Consent form error. Would be nice to have some proper logging
if (BuildConfig.BUILD_TYPE.equals("debug")) {
Toast.makeText(context, errorDescription, Toast.LENGTH_LONG).show();
}
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
consentForm.load();
}
private URL getPrivacyUrl() {
URL privacyUrl = null;
try {
privacyUrl = new URL(PRIVACY_URL);
} catch (MalformedURLException e) {
// Since this is a constant URL, the exception should never(or always) occur
e.printStackTrace();
}
return privacyUrl;
}
private void redirectToPaidVersion() {
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse(MARKET_URL_PAID_VERSION));
context.startActivity(i);
}
}
关于java - 谷歌同意 SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50540976/
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我编写了简单的 Java 应用程序供自己使用,它扫描 Excel 文档并从中提取一些事件。对于下一阶段,我希望它登录我的 Google 帐户并使用 Google Calendar API 创建这些事件
我有一个带有链接标记的复选框。单击链接标签时,我的模式打开。单击按钮然后选中复选框时我有模式 I agree with "Terms a
Consent SDK允许显示同意书,但目前只有英文版本(SDK 版本 1.0.3)。 SDK页面说: To update consent text of the Google-rendered co
您好,我需要一些关于如何应用丝潮cookie同意脚本的帮助http://silktide.com/cookieconsent/code 。 (由于欧盟 cookie 法等原因,我想对此进行广告)。现在
我收到了一封来自 Goolge 的关于在我的网站上实现 cookie 许可的电子邮件。我在 Play 商店中只发布了一个 Android 应用程序。它使用广告获利。有必要实现 cookie 同意消息吗
我正在尝试从 Youtube channel 检索 Youtube 视频列表,例如“https://www.youtube.com/user/YouTube/videos”,以获取第 n 个视频(感谢
我想抓取(使用 rvest )一个要求用户同意设置 cookie 的网站。如果我只是抓取页面,则 rvest 只会下载弹出窗口。这是代码: library(rvest) content % html_
我有一个 HTML 网站,我想向其中添加 Cookie-Consent。 类似于 Stackoverflow:Stackoverflow Screenshot 将会出现可能包含屏幕截图中所示链接的文本
我正在尝试将字符串与字符串向量匹配: a <- c('abcde', 'abcdf', 'abcdg') agrep('abcdh', a, max.distance=list(substitutio
我目前正在尝试集成 Google Consent SDK。onConsentInfoUpdated(consentStatus:ConsentStatus) 函数发生了一些我无法理解的事情 用户第一次
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭去年。 Im
我们在 Azure AD 中有一个使用 Microsoft Graph API 的应用。该应用程序使用 4 个基本权限成功运行:电子邮件、个人资料 User.Read User.ReadBasic.A
我们在 Azure AD 中有一个使用 Microsoft Graph API 的应用。该应用程序使用 4 个基本权限成功运行:电子邮件、个人资料 User.Read User.ReadBasic.A
此代码中未使用变量“status”。因此我无法检查用户的同意选择。 我必须将“状态数组”存储在默认值中。一旦当前状态在数组中可用,它将不会显示同意书。如果没有,那么我们将显示表单并将该状态添加到默认状
这是一个例子: 具体的实现可能有一些特定的行为,比如 ArrayList 的实现有 ensureCapacity(),它不适用于 LinkedList。 //programming to interf
我在一个网站上工作,我们目前有一个 cookie 横幅,它在启动时显示并有一个确定按钮。然而,我想改变这一点,让用户可以选择打开/关闭他们希望被跟踪的 cookie 类别。像这样: 我是 reactj
我正在使用 Mac OS X 10.9.5 和 git 版本 2.1.2。进入 推我收到: 同意 Xcode/iOS 许可证需要管理员权限,请通过 sudo 以 root 身份重新运行。 致命:无法从
搜索似乎只能找到使用 JavaScript 的解决方案。我想显示一个 Cookie 同意消息,即使访问者使用脚本拦截器也能看到它,所以我想知道这是否可以使用 CSS 和 HTML 来完成,而不需要任何
fun sample(list_of_str_lists, s) = case list_of_str_lists of [] => [] | x::[]
我是一名优秀的程序员,十分优秀!