开始 Android 编程 - 向应用程序添加广告

发布于 2024-09-27 06:54:54 字数 1039 浏览 3 评论 0原文

好的,我最近完成了我的第一个 Android 应用程序的大部分内容。它已经准备好上市了,但我想投放广告。我已经安装并注册了 AdWhirl,但根据他们的说明,我无法弄清楚如何实际显示广告。我发现了一些有帮助的资源(例如 http:// /malsandroid.blogspot.com/2010/05/admob-and-adwhirl.html),但实际上没有任何东西可以让我让广告发挥作用。我不确定是我的经验不足还是 AdWhirl 支持真的那么糟糕。

AdWhirl 支持人员表示:

4. 在您​​要添加广告的活动中:
● 导入com.adwhirl.AdWhirlLayout 包
● 使用类似于下面的代码片段添加AdWhirl 布局。

<代码> LinearLayout布局 = (LinearLayout) findViewById(R.id.layout_main);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "AdWhirl SDK 密钥");
relativeLayout.LayoutParams adWhirlLayoutParams =
新的RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
布局.addView(adWhirlLayout, adWhirlLayoutParams);
布局.invalidate();

我已将此代码添加到我的应用程序中,但无法显示任何广告。我确实导入了该包,并且我确实用我的 SDK 密钥替换了“AdWhirl SDK 密钥”位,所以我知道这不是问题。我是 ,任何关于这段代码的作用(或试图做什么)的见解都会非常有帮助。

想知道这个代码片段应该放在我的代码中的哪里,以及我应该如何修改这个代码片段以使广告发挥作用。无论如何 感谢您查看此内容...我真的很感激。

Okay, so I recently completed most of my first app for android. It's almost ready for the market, but I'd like to put in ads. I have installed and registered with AdWhirl, but I cannot figure out how to actually make ads show up, based on their instructions. I have found a few resources out there that help somewhat (such as http://malsandroid.blogspot.com/2010/05/admob-and-adwhirl.html ) but nothing that has actually let me make the ads work. I'm not sure if my inexperience is the issue or if the AdWhirl support is just that bad.

The AdWhirl support says:
"
4. In the Activity where you intend to add the ad:
● Import the com.adwhirl.AdWhirlLayout package
● Add an AdWhirl layout with a code snippet similar to below.


LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "AdWhirl SDK Key");
RelativeLayout.LayoutParams adWhirlLayoutParams =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
layout.addView(adWhirlLayout, adWhirlLayoutParams);
layout.invalidate();

"

I have added this code to my app, but I cannot get any ads to display. I DID import the package and I DID replace the "AdWhirl SDK Key" bit with my SDK Key so I know that is not the issue. I am wondering where this code snippet should be placed in my code and how I should modify this snippet to make ads work. Also, any insight as to what each piece of this code does (or is trying to do) would be extremely helpful.

Anyways, thanks for looking this over... I really appreciate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫竹語嫣☆ 2024-10-04 06:54:54

导致您出现问题的原因有多种:

  1. 广告可能是从服务器加载的,因此如果您的手机/avd 没有连接到互联网,那么您将看不到任何内容。检查 logcat,在这种情况下会出现一些异常。

  2. 可能是代码片段放置不正确。它应该被放置到您的 Activity 的 onCreate() 方法中,该方法使用 R.id.layout_main 作为布局。

  3. AdWhirl 网站上存在一些问题。但这不太可能。

无论如何,您并不限于使用 AdWhirl,因此您可以尝试其他广告提供商,例如 admob 和 smaato。

There are several causes to your problem:

  1. Ads is likely loaded from the server, so if there is no connection to the internet from your phone/avd, then nothing you will see. Check the logcat, some exceptions will be there in that case.

  2. May be the code snippet is placed incorrectly. It should be placed into onCreate() method of your activity, which uses R.id.layout_main as the layout.

  3. Some problems on AdWhirl site. But this is not likely.

Anyway, you are not stricted to use AdWhirl, so you may try another ads provider like admob and smaato.

梦行七里 2024-10-04 06:54:54

好吧,问题出在我通过 AdWhirl 使用的 AdMob 上。他们花了一些时间才开始向我发送广告,尽管我不确定为什么。

当我注意到广告出现在我之前编码的部分中时,我刚刚开始处理代码的其他部分。

因此,我想解决这个问题的技巧是确保您在 AdMob 和 AdWhirl 上拥有正确的所有密钥和 ID,然后稍等片刻,直到 AdMob 开始向您发送内容。另外,请确保您的广告不在带有内边距的布局内,因为这可能会导致它们无法显示。

Okay so the problem was with AdMob which I was using through AdWhirl. It took them a bit to begin sending me ads, although I'm not sure why.

I just started working on other parts of my code when I noticed that ads had appeared in the sections I had coded them into before.

So I guess the trick to this is to make sure you have all of your keys and IDs right on AdMob and AdWhirl, then sit back and wait for a bit until AdMob starts sending you stuff. Also, make sure your ads aren't inside a layout with padding as that will probably cause them to not show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文