简体   繁体   English

将 admob 集成到 Android 应用程序中

[英]Integrating admob into Android app

Been having some trouble trying to integrate the admob sdk into my application to display ads.尝试将 admob sdk 集成到我的应用程序中以显示广告时遇到了一些麻烦。 Im using the AdmobSDK version 4.1.0.我使用 AdmobSDK 4.1.0 版。 I've read loads of posts and there seems to be lacking some decent documentation and many discussions on the topic including http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1 So far my layout is..我已经阅读了大量的帖子,似乎缺乏一些像样的文档和关于该主题的许多讨论,包括http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli =1到目前为止,我的布局是..

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/scroll" 
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/linear" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <com.google.ads.AdView 
        android:id="@+id/ad" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        ads:adUnitId="MY_PUB_CODE" 
        ads:adSize="BANNER"/>       

</LinearLayout>
</ScrollView>

my androidmanifest.xml contains...我的 androidmanifest.xml 包含...

<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>

<meta-data android:value="MY_PUBLISHER_ID" android:name="ADMOB_PUBLISHER_ID"></meta-data>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

EDIT, UPDATE:编辑,更新:

Ok i seem to have gotten admob working on my HTC by adding,好的,我似乎已经通过添加 admob 在我的 HTC 上工作,

AdView ad = (AdView) findViewById(R.id.ad);
AdRequest r = new AdRequest()
r.addTestDevice("X3XFX518X7DE1FD879XA5XXAX1AX8BXX");
ad.loadAd(r);

however i only recieve a test banner, stating im ready to explore the google app galaxy.但是我只收到一个测试横幅,说明我准备好探索谷歌应用程序星系。 When i remove the "addTestDevice" method, the banner/ad does not show up atal and in the log i recieve, "ad not recieved due to lack of inventory".. Anyone sheed some light on this?当我删除“addTestDevice”方法时,横幅/广告没有显示,并且在我收到的日志中,“由于库存不足而没有收到广告”。有人对此有所了解吗?

thanks for the help so far!感谢你目前的帮助!

To your comment, I use this and it works quite well for me.根据您的评论,我使用它,它对我来说效果很好。 The size is the second param of the AdView constructor.大小是AdView构造函数的第二个参数。

ad = new AdView(this, AdSize.BANNER, "<ID>");
LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout);
// Add the adView to it
layout.addView(ad);
AdRequest request = new AdRequest();
request.setTesting(TESTING_MODE);
ad.loadAd(request);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM