2014-09-03 56 views
0

描述: - 根据Google的最新指南,我将我的应用与“Google Play服务”SDK集成在一起。早些时候它与独立的admob SDK集成在一起。Google Play服务:广告加载问题

问题: - 当显示其中一个广告时,横幅广告和完整广告会正常显示。但是,当两者都必须展示时,它们会产生不可预测的结果。

不可预知的结果? 是的,有时只有横幅正在加载,有时只显示完整的广告。他们都被证明是非常罕见的。

修正: - 1.我试图给与Banner和interstitial之间的一些延迟,并得到好一点的结果。但是大多数时候结果仍然不可预测。

  1. 我用非同步任务完整版的广告。在Background()中延迟2秒,并在PostExecute()中加载广告。它提供了更好的结果。但仍有10次尝试,只有7次显示广告。其余的3次横幅或全部或没有任何加载。

以下是主要活动

package com.example.adtest_new; 
import android.app.Activity; 
import android.content.Context; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.widget.Toast; 

import com.google.android.gms.ads.AdListener; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 
import com.google.android.gms.ads.InterstitialAd; 

public class MainActivity extends Activity 
{ 
Context myCont=null; 
private InterstitialAd interstitial = null; 
AdRequest adr; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    //Get the view from activity_main.xml 
    setContentView(R.layout.activity_main); 

    myCont = this; 

    //--------------BANNER AD----------------------------------  
    //Locate the Banner Ad in activity_main.xml 
    AdView adView = (AdView) this.findViewById(R.id.adView); 
    // Request for Ads 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    // Load ads into Banner Ads 
    adView.loadAd(adRequest); 
    //--------------BANNER AD----------------------------------   

//Fix-1 (Did not work) 
    try{Thread.sleep(2*1000);}catch(Exception e){}   

//Fix-2 (Did not work) 
//Called Asynch task here(put delay of 2 seconds in background() and loaded full ad in postexecute()) 

    //--------------FULL AD---------------------------------- 
    //Prepare the Interstitial Ad 
    interstitial = new InterstitialAd(MainActivity.this);   

    //Insert the Ad Unit ID 
    interstitial.setAdUnitId("ca-app-pub-465697675827xxxx/xxxxxxxxxx"); 
    adr = new AdRequest.Builder().build(); 
    //Load ads into Interstitial Ads 

    //Prepare an Interstitial Ad Listener 
    interstitial.setAdListener(new AdListener() 
    { 
     public void onAdLoaded() 
     { 
      //System.out.println("!!! Full Ad loaded !!!"); 
      Toast.makeText(myCont, "!!! Full Ad loaded !!!", Toast.LENGTH_SHORT).show(); 
      //Call displayInterstitial() function 
      displayInterstitial(); 
     } 
    });   
    interstitial.loadAd(adr);  
    //--------------FULL AD---------------------------------- 
}  

public void displayInterstitial() { 
    // If Ads are loaded, show Interstitial else show nothing. 
    if (interstitial.isLoaded()) 
    { 
     interstitial.show(); 
    } 
} 

}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/openedWindows" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ffffff" 
android:orientation="vertical" > 


<TextView 
    android:id="@+id/completePath" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:layout_marginTop="0dp" 
    android:layout_marginLeft="3dp" 
    android:text="/mnt/sdcard" 
    android:textColor="#ff2d8df1" 
    android:textSize="16dip" 
    android:textStyle="bold" 
    android:typeface="sans"/> 

<View 
android:id="@+id/bar0" 
android:layout_width="fill_parent" 
android:layout_height="1dp" 
android:layout_marginTop="0dp" 
android:background="#ffb2cb39"  
android:layout_marginBottom="0dp"/> 



<View 
android:id="@+id/bar1" 
android:layout_width="fill_parent" 
android:layout_height="1dp" 
android:layout_marginTop="0dp" 
android:background="#ffb2cb39"  
android:layout_marginBottom="1dp"/> 


<RelativeLayout  
android:id="@+id/temp" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/transparent" 
android:layout_marginTop="5dp" 
android:layout_marginBottom="5dp" 
android:orientation="vertical"> 

<Button 
    android:id="@+id/selectAll" 
    android:layout_width="wrap_content" 
    android:layout_height="25dp" 
    android:layout_gravity="left" 
    android:layout_marginBottom="1dp" 
    android:layout_marginLeft="15dp" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/button_green" 
    android:textSize="15dip" 
    android:text="BUTTON1" 
    android:paddingLeft="10px" 
    android:paddingRight="10px" 
    android:textColor="#ffffff" 
    android:textStyle="bold" /> 

<Button 
    android:id="@+id/selectBtn" 
    android:layout_width="wrap_content" 
    android:layout_height="25dp" 
    android:layout_marginRight="15dp" 
    android:layout_marginBottom="1dp" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/button_green" 
    android:textSize="15dip" 
    android:text="BUTTON2" 
    android:paddingLeft="10px" 
    android:paddingRight="10px" 
    android:textColor="#ffffff" 
    android:textStyle="bold" /> 
</RelativeLayout> 


<View 
android:layout_width="fill_parent" 
android:layout_height="1dp" 
android:layout_above="@+id/tableRow2" 
android:background="#444444"  
android:layout_marginBottom="0dp"/> 

<TableRow 
android:id="@+id/tableRow2" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-465697675827xxxx/xxxxxxxxxx" 
    />  
</TableRow> 

</LinearLayout> 

清单的代码

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.adtest_new" 
    android:versionCode="1" 
    android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="9" 
    android:targetSdkVersion="21" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <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"/> 

</application> 

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

</manifest> 

请让我知道如何解决这个问题? 独立admob SDK适用于两种广告类型。

回答

0

我看到你加载“真实”的广告(即没有测试广告),只要你不申报的测试设备。我不是100%确定我要说什么,但这可能是问题的原因。当显示内容的广告,我想你不会总是有来自AdMob /谷歌提供的广告播放服务,所以有时你会不会有广告显示出来(我想加载错误代码是3,这是“无填充颜色”)。您可以在声明测试设备时进行测试,这会导致使用始终可用的测试广告。

此外,建议使用测试设备,同时深化发展,因为如果你点击了很多自己的广告(由于失误或只是为了测试),你可能来自AdMob被禁止。

要了解如何添加测试设备,比照本

测试广告

发展过程中应使用测试广告,以避免产生错误的印象 。此外,您始终可以依靠可用的测试广告 。通过将散列的设备ID传递给 AdRequest.Builder来设置测试广告。addTestDevice:在AdRequest请求=新 AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)//所有模拟器 .addTestDevice( “AC98C820A50B4AD8A2106EDE96FB87D4”)//我的Galaxy Nexus手机测试 .build();

logcat会dev的

冰的MD5哈希ID为方便起见,例如:使用 AdRequest.Builder.addTestDevice( “AC98C820A50B4AD8A2106EDE96FB87D4”)在此设备上 取得测试广告。

https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner

要小心,有些人说,如果你的手机是不是英语,测试广告和不正常工作(AdMob test ads shows only on English devices

编辑:当然,你的应用程序的真实用户使用真实的广告,所以他们也可能遇到并不总是可用广告的“问题”,但这是正常的。您仍然可以按时重新安排新的负载(对于插页式广告,横幅会定期重新加载)以尝试应对我的猜测。

编辑2:顺便说一下,这可能与您的问题有点不相关,但人们通常强烈建议不要显示AdListener.onAdLoaded方法中的广告,而是在您希望的时候手动调用此方法显示(如果isLoaded为true)。但这只是一个人体工程学的考虑,没有错误 - 明智之一