Android中的AdMob集成

Android中的AdMob集成,android,admob,Android,Admob,我正在我的应用程序中实现AdMob。我添加了xml代码 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.google.android.gms.ads.AdView android:id="@+id/adView" a

我正在我的应用程序中实现AdMob。我添加了xml代码

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="350dp"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-2415896980984028/6183643605" >
    </com.google.android.gms.ads.AdView>

</LinearLayout>

我不知道到底是什么问题。

您在manifest.xml中添加了这个吗

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<activity android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />


您添加了lib吗?

您必须在活动中编写代码

  private AdView adView;
    private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
    layout.addView(adView);

    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
必须在Menifest上刊登这一行广告

  <activity android:name="com.google.android.gms.ads.AdActivity"
   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
   <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

由于您正在通过google play服务库使用admob,请添加/进行以下更改:

在布局中,将ad xml命名空间更改为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

   -----/>

致:


然后在清单的应用程序标记中,更改:

<activity android:name="com.google.ads.AdActivity"/>

致:


加:


不要忘记权限:

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


请在清单+
xmlns:ads=”中使用crashlogCheck权限添加LogCat输出http://schemas.android.com/apk/lib/com.google.ads“
在布局中。是。是的。我已经添加了Lib(谷歌播放服务)并在清单中添加了这些内容。@MehediHassan你检查了logCat吗?@MehediHassan让我们做一件事,从这里下载源代码,然后用xml输入你的Aduntid并检查发生了什么。@Parachouhan你的解决方案是错误的,因为他使用了新的admob。您已经提供了过时的api。@Mehedi Hassan,从你的libs文件夹中删除admob sdk jar,做一个项目清理并查看我的回答是的,我没有工作。谢谢。实际上我忘了添加。。
<activity android:name="com.google.ads.AdActivity"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="android.permission.INTERNET"/>