问题增加新的AdMob为Android应用程序 [英] Problems adding new AdMob to android app
问题描述
我想新的AdMob的广告添加到我的第一个应用程序,我设法安排code以正确的方式,但我有一些问题:
第一个问题是我的广告ID的 CA-APP-酒馆61413779example 越来越多的错误,如:钙不能被解析为一个变量, BA 不能被解析为一个变量,字面 类型 61413779 int是超出范围。
第二个问题是R.id. mainLayout ,这是mainLayout,我不明白这一点。
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_basic_screen);
//创建AD浏览报
AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,CA-APP-酒馆61413779example);
//查找您的LinearLayout假设它是被赋予了
//属性机器人:ID =@ + ID / mainLayout
的LinearLayout布局=(的LinearLayout)findViewById(R.id.mainLayout);
// AD浏览报给它添加
layout.addView(AD浏览报);
adView.loadAd(新AdRequest());
//初始化一个通用的请求与广告加载
adView.loadAd(新AdRequest());
我不熟悉你的AdMob加入的方式,但我得到了另一种伟大的方式使用XML AdMob的添加到您的应用程序而已。
第一在清单中添加这些权限
<使用-权限的Android:名称=android.permission.ACCESS_NETWORK_STATE/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
* 第二个是最重要的。
然后在清单中添加此应用程序中
标记
<活动机器人:名称=com.google.ads.AdActivity
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
现在在每一个活动中,您希望您在活动layout.xml添加该广告出现
< com.google.ads.AdView
机器人:ID =@ + ID /广告
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
广告:adUnitId =XXXXXXXXXXXX
广告:adSize =大旗
广告:loadAdOnCreate =真
机器人:layout_gravity =中心
机器人:layout_margin =10dp>
< /com.google.ads.AdView>
和顶部父布局的前内侧。 LinearLayout中添加了这些的下的xmlns:机器人=XXX 的
的xmlns:广告=http://schemas.android.com/apk/lib/com.google.ads
的xmlns:工具=http://schemas.android.com/tools
现在的广告应该很好地工作:D
更新:不要忘记下载并放置的 GoogleAdMobAdsSdk-6.4.1.jar 的下libs文件夹
I am trying to add the new AdMob ads to my first application, I managed to arrange the code in the correct way but I have to problems:
First problem is my ad ID ca-app-pub-61413779example is getting multiple errors like: ca cannot be resolved to a variable, ba cannot be resolved to a variable, the literal 61413779 of type int is out of range.
The second problem is R.id.mainLayout, which is mainLayout, I don't get it.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic_screen);
// Create the adView
adView = new AdView(this, AdSize.BANNER, ca-app-pub-61413779example);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
adView.loadAd(new AdRequest());
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
I'm not familiar with your admob adding way, but I got another great way to add admob to your app using xml only.
first in your manifest add these permissions
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
* the second is most important
then add this in your manifest inside the application
tag
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
now in every activity you want the ad to appear on you add this in the layout.xml of the activity
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_gravity="center"
android:layout_margin="10dp">
</com.google.ads.AdView>
and inside the top parent layout ex. linearlayout you add these under xmlns:android="xxx
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
now the ads should work perfectly :D
UPDATE: don't forget to download and place the GoogleAdMobAdsSdk-6.4.1.jar under the libs folder.
这篇关于问题增加新的AdMob为Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!