android - 为什么当我添加 GDPR EU 同意时我的应用程序 android 崩溃?

标签 android android-studio

我将 GDPR 代码添加到我的应用程序中,但它崩溃了。

这是我的功能:

private void loadGPDR() {

        ConsentInformation consentInformation = ConsentInformation.getInstance(this);
        String[] publisherIds = {"yyyyyyyyyyyyyy"};
        consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
            @Override
            public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                // User's consent status successfully updated.
            }

            @Override
            public void onFailedToUpdateConsentInfo(String errorDescription) {
                // User's consent status failed to update.
            }
        });
        URL privacyUrl = null;
        try {
            // TODO: Replace with your app's privacy policy URL.
            privacyUrl = new URL("https://sites.google.com/view/yyyyyyyyyy");
        } catch (MalformedURLException e) {
            e.printStackTrace();
            // Handle error.
        }
        form = new ConsentForm.Builder(this, privacyUrl)
                .withListener(new ConsentFormListener() {
                    @Override
                    public void onConsentFormLoaded() {
                        // Consent form loaded successfully.
                        form.show();
                    }

                    @Override
                    public void onConsentFormOpened() {
                        // Consent form was displayed.
                    }

                    @Override
                    public void onConsentFormClosed(
                            ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                        // Consent form was closed.
                    }

                    @Override
                    public void onConsentFormError(String errorDescription) {
                        // Consent form error.
                    }
                })
                .withPersonalizedAdsOption()
                .withNonPersonalizedAdsOption()
                .withAdFreeOption()
                .build();
        form.load();
    }

错误:

Process: com.code.myapplication, PID: 28444
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.code.myapplication/com.code.myapplication.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
        at android.app.ActivityThread.access$900(ActivityThread.java:154)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5294)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)
     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
        at android.content.res.Resources.getText(Resources.java:321)
        at android.content.res.XResources.getText(XResources.java:837)
        at android.content.res.Resources.getString(Resources.java:407)
        at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
        at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
        at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
        at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
        at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
        at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
        at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
        at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
        at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
        at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
        at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
        at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
        at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
        at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
        at android.webkit.WebView.<init>(WebView.java:554)
        at android.webkit.WebView.<init>(WebView.java:489)
        at android.webkit.WebView.<init>(WebView.java:472)
        at android.webkit.WebView.<init>(WebView.java:459)
        at android.webkit.WebView.<init>(WebView.java:449)
        at com.google.ads.consent.ConsentForm.<init>(ConsentForm.java:80)
        at com.google.ads.consent.ConsentForm.<init>(ConsentForm.java:46)
        at com.google.ads.consent.ConsentForm$Builder.build(ConsentForm.java:210)
        at com.code.myapplication.MainActivity.loadGPDR(MainActivity.java:70)
        at com.code.myapplication.MainActivity.onCreate(MainActivity.java:18)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)

最佳答案

Belyamani Said 的评论对我有用。 只需更新 appcompat 库:

来自:

implementation 'androidx.appcompat:appcompat:1.1.0'

到:

implementation 'androidx.appcompat:appcompat:1.2.0-alpha03'

关于android - 为什么当我添加 GDPR EU 同意时我的应用程序 android 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58440781/

相关文章:

java - GraphView 垂直标签从 0 开始以整数递增

java - Gradle 项目同步失败。基本功能 - 在 Android Studio 2.2 上失败

android - 错误类型3-错误: Activity 类MainActivity不存在

Android Studio Emulator 卡住并始终加载

android - 错误 :(47, 0) 无法为 com.android.build.gradle.AppExtension 类型的对象获取未知属性 'IS_CI_BUILD'

Android - 如何从用户选择的歌曲创建 MediaPlayer

android - 如何在按下按钮时重复做某事?

android - 在 Visual Studio 中创建新的 native 应用程序 (Android) 时出错

android - 在 Android 中干净地声明和使用变量

android - admob 可以在 sdk 2.2 上运行吗?无法编译项目