gpt4 book ai didi

android - Adview loadAd() 触发 StrictMode 违规

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:36 27 4
gpt4 key购买 nike

我正在尝试在我的应用程序中添加一些内容。当我启用 StrictMode 时,我遇到了一堆像这样的违反政策的行为(可能有 6 或 7 个)。这是正常的吗?

18817-18817/com.xyz.xyz.xyz D/StrictMode: StrictMode policy violation; ~duration=67937 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=5439503 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1263)
at libcore.io.BlockGuardOs.fstat(BlockGuardOs.java:132)
at java.io.RandomAccessFile.length(RandomAccessFile.java:240)
at java.util.zip.ZipFile.readCentralDir(ZipFile.java:386)
at java.util.zip.ZipFile.<init>(ZipFile.java:175)
at java.util.zip.ZipFile.<init>(ZipFile.java:142)
at android.webkit.WebViewFactory.getLoadFromApkPath(WebViewFactory.java:357)
at android.webkit.WebViewFactory.getWebViewNativeLibraryPaths(WebViewFactory.java:407)
at android.webkit.WebViewFactory.loadNativeLibrary(WebViewFactory.java:511)
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:188)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:158)
at android.webkit.WebSettings.getDefaultUserAgent(WebSettings.java:1239)
at com.google.android.gms.ads.internal.util.ai.a(:com.google.android.gms.DynamiteModulesA:414)
at com.google.android.gms.ads.internal.util.y.a(:com.google.android.gms.DynamiteModulesA:419)
at com.google.android.gms.ads.internal.state.h.a(:com.google.android.gms.DynamiteModulesA:349)
at com.google.android.gms.ads.internal.a.<init>(:com.google.android.gms.DynamiteModulesA:153)
at com.google.android.gms.ads.internal.c.<init>(:com.google.android.gms.DynamiteModulesA:104)
at com.google.android.gms.ads.internal.c.<init>(:com.google.android.gms.DynamiteModulesA:92)
at com.google.android.gms.ads.internal.g.<init>(:com.google.android.gms.DynamiteModulesA:55)
at com.google.android.gms.ads.internal.o.<init>(:com.google.android.gms.DynamiteModulesA:89)
at com.google.android.gms.ads.ChimeraAdManagerCreatorImpl.newAdManagerByType(:com.google.android.gms.DynamiteModulesA:66)
at com.google.android.gms.ads.internal.client.al.onTransact(:com.google.android.gms.DynamiteModulesA:91)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.ads.internal.client.am.newAdManagerByType(:com.google.android.gms:170)
at com.google.android.gms.ads.AdManagerCreatorImpl.newAdManagerByType(:com.google.android.gms:90)
at com.google.android.gms.ads.internal.client.al.onTransact(:com.google.android.gms:91)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.ads.internal.client.zzv$zza$zza.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zze.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzl$1.zzim(Unknown Source)
at com.google.android.gms.ads.internal.client.zzl$1.zzin(Unknown Source)
at com.google.android.gms.ads.internal.client.zzl.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzl.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzae.zzjn(Unknown Source)
at com.google.android.gms.ads.internal.client.zzae.zzjm(Unknown Source)
at com.google.android.gms.ads.internal.client.zzae.zza(Unknown Source)
at com.google.android.gms.ads.BaseAdView.loadAd(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at com.xyz.xyz.xyz.MainActivity.LoadAd(MainActivity.java:539)
at com.xyz.xyz.xyz.MainActivity.onCreate(MainActivity.java:323)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:72

adview 的代码是这样的:

private void LoadAd(){
Log.d(TAG, "LoadAd() called");
mAdView = new AdView(this);
//Finds an ad that best fits a user's device.
LinearLayout adContainer = (LinearLayout) findViewById(R.id.adView_container);
mAdView.setAdSize(Utils.getBannerSize(this));
mAdView.setAdUnitId(getString(R.string.banner_ad_unit_id));
adContainer.addView(mAdView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}

最佳答案

如果您通过 detectAll()detectDiskReads() 将 StrictMode 设置为检测 DiskReads,则当应用程序读取磁盘时会发生 StrictMode 违规。

我认为 DiskReads 在正常情况下不是问题。所以你可以像下面这样禁用这种违规行为:

StrictMode.ThreadPolicy threadPolicy = new StrictMode.ThreadPolicy.Builder()
. ...
.permitDiskReads()
.permitDiskWrites() // If you also want to ignore DiskWrites, Set this line too.
. ...
.build();

StrictMode.setThreadPolicy(threadPolicy);

关于android - Adview loadAd() 触发 StrictMode 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38930737/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com