描述:-我正在根据谷歌的最新指导原则将我的应用程序与“谷歌Play Service”SDK集成。早些时候,它与独立的admob SDK集成。
问题:-当其中一个广告被显示时,横幅广告和完整广告被正确显示。但当两者都必须显示时,它们会产生不可预测的结果。
不可预测的结果?是的,有时只有横幅正在加载,有时只有完整的广告显示。这是非常罕见的,他们都显示。
修复:-1。我尝试在Banner和Interstitual之间进行一些延迟,但没有得到更好的结果。但大多数时候,结果仍然是不可预测的。
以下是主要活动的代码
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\u 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>
请让我知道如何解决这个问题??独立的admobSDK适用于两种广告类型。
我看到您正在加载“真实”广告(即不是测试广告),因为您没有声明测试设备。我不是100%确定我要说什么,但这可能是问题的原因。在显示真实广告时,我认为您不会总是有来自Admob/Google Play Services的可用广告,因此有时您不会显示广告(我认为加载错误代码为3,即“无填充”)。您可以在声明测试设备时进行测试,这会导致使用始终可用的测试广告。
此外,建议在开发时使用测试设备,因为如果您在自己的广告上点击了很多(错误地或只是为了测试),您可能会被禁止使用AdMob。
要查看如何添加测试设备,请参阅以下内容
测试广告
您应该在开发过程中使用测试广告以避免产生错误印象。此外,您始终可以指望测试广告可用。通过将您的散列设备ID传递给AdRequest来设置测试广告。Builder.addTestDevice:AdRequest Request=new AdRequest。Builder(). addTestDevice(AdRequest.DEVICE_ID_EMULATOR)//All仿真器. addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4")//My Galaxy Nexus test phone. build();
logcat将打印开发人员
ice的MD5哈希ID为方便起见,例如:使用AdRequest。建设者添加测试设备(“AC98C820A50B4AD8A2106EDE96FB87D4”)以获取此设备上的测试广告。
(https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner)
注意有些人说测试广告不能正常工作,如果你的手机不是英语(AdMob测试广告只显示在英语设备上)
编辑:当然,你的应用程序的真实用户会使用真实的广告,因此他们也可能会遇到广告不总是可用的“问题”,但这是正常的。我想,你仍然可以定期安排新的加载(对于间隙,横幅会定期重新加载),以应对这种情况。
编辑2:顺便说一下,这可能与你的问题有点无关,但人们通常强烈建议不要显示AdListener的广告。onAdLoaded方法,但要在希望显示它时手动调用它(如果isLoaded为true)。但这只是一个从功能角度考虑的问题,不是一个明智的错误
我正试图加载Admob原生广告。以前(在应用程序更新之前)广告经常显示,但现在它们不显示了。我已经在下面发布了代码、xml和Logcat。 代码 洛克卡特
我正在做一个webview应用程序。我有一个问题:“使用Chrome自定义选项卡时会出现adsense广告,但使用常规webview时不会出现adsense广告。”在正常的webview中,如何允许广告? 示例i. mage 网络视图。getSettings()。setUserAgentString(“Mozilla/5.0(Linux;Android 4.4;Nexus 5 Build/Buil
问题内容: 目标 我正在开发一个运行Linux的简单设备。它具有BLE功能,而我目前正在使用bluez 5.8。 我想使用iPhone在此设备上触发操作。 已经工作的内容: 我可以使iPhone“看到”该设备。 iPhone也连接到设备。 我在linux上设置了这样的蓝牙设备: iOS代码非常简单: 在iPhone上运行此代码时,出现以下日志: 因此,看来iPhone可以正常连接,但看不到任何服务
我最近收到了一封电子邮件更新,AdMob将于2016年10月17日停止向此链接https://firebase . Google . com/docs/AdMob/Android-legacy-release-notes中列出的SDK版本提供广告,并且必须修改为此链接https://firebase . Google . com/docs/AdMob/release-notes # Android
我正在尝试使用Admob在我的android应用程序中显示奖励视频广告。如果我用谷歌示例广告单元ID运行应用程序,它工作得很好,但如果我将其更改为我的奖励广告单元ID,则不会加载广告。