gpt4 book ai didi

android - AdMob 广告未在 Android SDL 应用中正确显示

转载 作者:太空宇宙 更新时间:2023-11-03 12:52:10 25 4
gpt4 key购买 nike

我在我的应用中实现 AdMob 广告时遇到了问题。我正在使用 SDL和 native 代码。广告是在 onCreate 方法中创建的,如下所示:

@Override
protected void onCreate(Bundle savedInstanceState)
{
Log.v("SDL", "onCreate():" + mSingleton);
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

SDLActivity.initialize();
mSingleton = this;

mSurface = new SDLSurface(getApplication());
mLayout = new RelativeLayout(this);

adView = new AdView( this );
adView.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX");
adView.setAdSize(AdSize.BANNER);

request = new AdRequest.Builder()
.addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.build();

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.loadAd(request);

mLayout.addView(mSurface);
mLayout.addView(adView, params);

setContentView(mLayout);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

我认为这段代码是正确的,因为广告位于屏幕上,但它不可见。我可以触摸屏幕上应该显示广告的位置,然后浏览器开始打开,因此广告实际上已加载。

然后广告将在以下情况下正确显示:

  • 是时候刷新了(在 AdMob 帐户上设置,我设置了 30 秒)
  • Activity 类调用 onPauseonResume 方法时,我退出应用程序然后恢复

我一直在想一些刷新的方法,但找不到解决这个问题的方法。我试过的这种方法:

adView.refreshDrawableState();
adView.setActivated( true );
adView.setEnabled( true );
adView.setFocusable( true );
adView.setHovered( true );
adView.showContextMenu();

我不知道还能做什么。有什么建议吗?

更新

我已经检查了我的 logcat 输出,但没有发现任何奇怪的地方:

1.  I/ActivityManager(  644): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.libsdl.app/.SDLActivity bnds=[184,839][360,1062]} from pid 12651
2. I/ActivityManager( 644): Start proc org.libsdl.app for activity org.libsdl.app/.SDLActivity: pid=24024 uid=10123 gids={50123, 3003, 1028, 1015}
3. W/linker (24024): libopenal.so has text relocations. This is wasting memory and is a security risk. Please fix.
4. I/LibraryLoader(24024): Expected native library version number "",actual native library version number ""
5. I/chromium(24024): [INFO:library_loader_hooks.cc(116)] Chromium logging enabled: level = 0, default verbosity = 0
6. I/BrowserStartupController(24024): Initializing chromium process, renderers=0
7. E/AudioManagerAndroid(24024): BLUETOOTH permission is missing!
8. W/Adreno-GSL(24024): <get_panel_settings:3802>: Android framework reported version 2. So, don't force ES30
9. I/Adreno-EGL(24024): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
10. I/Adreno-EGL(24024): OpenGL ES Shader Compiler Version: 17.01.10.SPL
11. I/Adreno-EGL(24024): Build Date: 11/06/13 Wed
12. I/Adreno-EGL(24024): Local Branch:
13. I/Adreno-EGL(24024): Remote Branch:
14. I/Adreno-EGL(24024): Local Patches:
15. I/Adreno-EGL(24024): Reconstruct Branch:
16. I/Ads (24024): Starting ad request.
17. I/ActivityManager( 644): Displayed org.libsdl.app/.SDLActivity: +1s113ms
18. I/ActivityManager( 644): Process com.android.musicfx (pid 18286) has died.
19. E/rsC++ (12651): RS Message thread exiting.
20. I/OpenAL (24024): _SC_NPROCESSORS_ONLN=2
21. I/dalvikvm-heap(10840): Grow heap (frag case) to 6.923MB for 1127536-byte allocation
22. I/chromium(10840): [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
23. I/chromium(10840): [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
24. I/chromium(10840): [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
25. I/dalvikvm-heap(24024): Grow heap (frag case) to 4.740MB for 1127536-byte allocation
26. W/chromium(24024): [WARNING:proxy_service.cc(890)] PAC support disabled because there is no system implementation
27. I/Ads (24024): Scheduling ad refresh 60000 milliseconds from now.
28. I/Ads (24024): Ad finished loading.
29. W/ActivityThread(24024): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
30. W/KInfoc (23003): The data section count is not equal! table:fm_public, count in format:13, count in data:14.
31. W/KInfoc (23003): The data section count is not equal! table:fm_public, count in format:13, count in data:14.
32. I/wpa_supplicant(25610): wlan0: WPA: Group rekeying completed with 00:21:27:da:a8:64 [GTK=TKIP]
33. W/Uploader(29884): No account for auth token provided
34. W/Uploader(29884): No account for auth token provided
35. W/Uploader(29884): No account for auth token provided
36. I/wpa_supplicant(25610): wlan0: WPA: Group rekeying completed with 00:21:27:da:a8:64 [GTK=TKIP]
37. I/Ads (24024): Starting ad request.
38. I/chromium(10840): [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
39. I/chromium(10840): [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
40. I/chromium(10840): [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
41. I/Ads (24024): Scheduling ad refresh 60000 milliseconds from now.
42. I/Ads (24024): Ad finished loading.
43. W/AwContents(24024): nativeOnDraw failed; clearing to background color.

在第 16 行,广告开始请求,在第 28 行,有一条消息表明广告已完成加载,但未显示在屏幕上。60 秒后开始另一个请求(第 37 行),完成后广告出现在屏幕上。最后一行提示nativeOnDraw failed,不知道是不是跟这个有关系?

最佳答案

我只是通过设置背景颜色解决了这个问题:

adView.loadAd(request);
adView.setBackgroundColor(Color.TRANSPARENT);

mLayout.addView(mSurface);
mLayout.addView(adView, params);

关于android - AdMob 广告未在 Android SDL 应用中正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28387329/

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