简体   繁体   English

广告将不会显示,Android(AdMob)

[英]Ad will not show, android (AdMob)

I have been trying to get my advert to show, but it will not show....I just keep getting the below errors, but I am not sure what they mean. 我一直试图让我的广告显示出来,但它不会显示....我一直在收到以下错误,但我不确定它们是什么意思。 I have imported the google-play services correctly. 我已经正确导入了Google Play服务。

Any help will be great, thanks! 任何帮助将是巨大的,谢谢!

UPDATE UPDATE

I have solved it. 我已经解决了。

The error which was causing it to stop was the 'No enough space', this was due to me using the linear layout. 导致其停止的错误是“空间不足”,这是由于我使用了线性布局。 Upon switching to a relative Layout, it worked fine. 切换到相对布局后,它运行良好。

Main.java: Main.java:

package com.example.f;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
//import com.google.android.gms.samples.ads.R;
//import com.google.android.gms.samples.ads.ToastAdListener;


public class MainActivity extends ActionBarActivity {

     private AdView adView;
     //This is the unit ID I get from admob account right?
     private static final String AD_UNIT_ID = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
        layout.addView(adView);

        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);  

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onResume() {
      super.onResume();
      if (adView != null) {
        adView.resume();
      }
    }

    @Override
    public void onPause() {
      if (adView != null) {
        adView.pause();
      }
      super.onPause();
    }

    /** Called before the activity is destroyed. */
    @Override
    public void onDestroy() {
      // Destroy the AdView.
      if (adView != null) {
        adView.destroy();
      }
      super.onDestroy();
    }
}

main.xml file: main.xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
   android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.f.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                           android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           ads:adSize="BANNER"
                           ads:adUnitId=""

                           />

</LinearLayout>

LogCat: logcat的:

08-31 17:32:36.309: W/ApplicationPackageManager(8370): getCSCPackageItemText()
08-31 17:32:36.429: D/dalvikvm(8370): DexOpt: --- BEGIN 'ads-1174894372.jar' (bootstrap=0) ---
08-31 17:32:36.439: I/Ads(8370): Starting ad request.
08-31 17:32:36.439: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:32:36.449: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:32:36.459: V/WebViewChromium(8370): Binding Chromium to the background looper Looper (main, tid 1) {42d13f70}
08-31 17:32:36.459: I/chromium(8370): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
08-31 17:32:36.459: I/BrowserProcessMain(8370): Initializing chromium process, renderers=0
08-31 17:32:36.469: W/chromium(8370): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
08-31 17:32:36.469: W/ApplicationPackageManager(8370): getCSCPackageItemText()
08-31 17:32:36.479: I/Adreno-EGL(8370): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build:  (CL3869936)
08-31 17:32:36.479: I/Adreno-EGL(8370): OpenGL ES Shader Compiler Version: 17.01.11.SPL
08-31 17:32:36.479: I/Adreno-EGL(8370): Build Date: 01/17/14 Fri
08-31 17:32:36.479: I/Adreno-EGL(8370): Local Branch: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Remote Branch: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Local Patches: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Reconstruct Branch: 
08-31 17:32:36.549: D/dalvikvm(8370): DexOpt: --- END 'ads-1174894372.jar' (success) ---
08-31 17:32:36.549: D/dalvikvm(8370): DEX prep '/data/data/com.example.f/cache/ads-1174894372.jar': unzip in 0ms, rewrite 120ms
08-31 17:32:36.579: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.589: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:36.619: D/OpenGLRenderer(8370): Enabling debug mode 0
08-31 17:32:36.689: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 11
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 12
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 13
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 14
08-31 17:32:36.699: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.729: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.739: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:38.531: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:38.531: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:32:38.531: I/Ads(8370): Ad finished loading.
08-31 17:33:38.540: I/Ads(8370): Starting ad request.
08-31 17:33:38.540: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:33:38.550: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:33:38.580: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:38.590: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.610: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.650: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.660: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:39.901: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:33:39.901: I/Ads(8370): Ad finished loading.
08-31 17:33:39.911: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.911: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.931: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.931: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.951: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.951: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:40.001: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:39.899: I/Ads(8370): Starting ad request.
08-31 17:34:39.899: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:34:39.909: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:34:39.950: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.000: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.020: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.030: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:41.321: I/dalvikvm(8370): Total arena pages for JIT: 15
08-31 17:34:41.531: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.541: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:34:41.541: I/Ads(8370): Ad finished loading.
08-31 17:34:41.551: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.551: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.611: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.

The Problem is Admob Ads need 320X50 dp space in order to show in your app 问题是Admob广告需要320X50 dp的空间才能在您的应用中展示

you have used relativelayout BUT if you try to change these values 如果您尝试更改这些值,则已使用relativelayout BUT

android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"

which are located in dimens.xml change it to 50dp for example, you will see that the ads will not show up. 例如,位于dimens.xml中的文件将其更改为50dp ,您将看到广告不会展示。

the point here is no matter what kind of layouts you use the important things is make sure the space is 320X50 dp and this can be found in dimens.xml 这里的要点是无论您使用哪种布局,重要的是确保空间为320X50 dp,并且可以在dimens.xml中找到。

AdSize.BANNER is 320X50 dp. AdSize.BANNER为320X50 dp。

For your smaller device, instead of 对于较小的设备,而不是

adView.setAdSize(AdSize.BANNER);

You can use: 您可以使用:

adView.setAdSize(new AdSize(286, 50));

I had a similar problem and from this line: 我有一个类似的问题,从这一行:

Not enough space to show ad. 没有足够的空间来展示广告。 Needs 320x50 dp, but only has 286x535 dp. 需要320x50 dp,但只有286x535 dp。

Your log above shows that the there is enough height but not enough width. 上面的日志显示,高度足够但宽度不够。 Therefore you have to ensure that the properties listed below allows enough width for your ad to show. 因此,您必须确保下面列出的属性允许足够的宽度来展示您的广告。 So you can just set them to zero for the first two as shown below and do something appropriate for the last. 因此,您可以如下所示将前两个设置为零,然后对后一个进行适当的设置。

android:paddingLeft="0dp"
android:paddingRight="0dp" and 
android:layout_width

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

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