描述: - 根據Google的最新指南,我將我的應用與「Google Play服務」SDK集成在一起。早些時候它與獨立的admob SDK集成在一起。Google Play服務:廣告加載問題
問題: - 當顯示其中一個廣告時,橫幅廣告和完整廣告會正常顯示。但是,當兩者都必須展示時,它們會產生不可預測的結果。
不可預知的結果? 是的,有時只有橫幅正在加載,有時只顯示完整的廣告。他們都被證明是非常罕見的。
修正: - 1.我試圖給與Banner和interstitial之間的一些延遲,並得到好一點的結果。但是大多數時候結果仍然不可預測。
- 我用非同步任務完整版的廣告。在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適用於兩種廣告類型。