插页式未加载。?
Interstitial not loading.?
public class MainActivity extends ActionBarActivity {
InterstitialAd mInterstitialAd;
@Override
public void onBackPressed() {
ShowAd();
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
//mInterstitialAd.setAdUnitId(String.valueOf(R.string.interstitial_ad_unit_id));
//mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
mInterstitialAd.setAdUnitId("ca-app-pub-6342248862135370/7323606247");
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(),"Ad Failed To Load", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLoaded() {
Toast.makeText(getApplicationContext(),"Ad Loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed(){requestNewInterstitial();}
});
//Load Ad Starts
AdView mAdView=(AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//Load Ad Stops
}
public void second(View view){
Intent i = new Intent(getApplicationContext(), second.class);
startActivity(i);
}
public void ShowAd(){
if(mInterstitialAd.isLoaded()){
Toast.makeText(getApplication(), "The Ad has Loaded.", Toast.LENGTH_SHORT).show();
mInterstitialAd.show();
}
else
Toast.makeText(getApplication(), "The Ad has not loaded yet.", Toast.LENGTH_SHORT).show();
}
public void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
我的问题是它总是显示 toast "Ad failed to Load"。我不知道我的代码中缺少什么。请帮忙!!。我已经对此进行了很多搜索,所以请不要 post 链接到其他问题。
清单
<?xml version="1.0" encoding="utf-8"?>
<!-- Include required permissions for Google Mobile Ads to run -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<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>
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name=".second"
android:label="@string/title_activity_second"></activity>
<activity
android:name=".third"
android:label="@string/title_activity_third"></activity>
</application>
LogCat
Logcat 清楚地说:
06-01 00:59:20.883 16251-16326/abc.myapplication I/Ads﹕ No fill from ad server.
这就是您没有收到任何广告的原因。此时、地点和设备有 none 可供您使用。如果你想测试你需要设置测试 adUnitId。这也由 logcat:
给出
06-01 00:59:20.159 16251-16251/abc.myapplication I/Ads﹕ Use AdRequest.Builder.addTestDevice("1CC3C3CDC4D015059D600FE0D095EAE5") to get test ads on this device.
public class MainActivity extends ActionBarActivity {
InterstitialAd mInterstitialAd;
@Override
public void onBackPressed() {
ShowAd();
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
//mInterstitialAd.setAdUnitId(String.valueOf(R.string.interstitial_ad_unit_id));
//mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
mInterstitialAd.setAdUnitId("ca-app-pub-6342248862135370/7323606247");
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(),"Ad Failed To Load", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLoaded() {
Toast.makeText(getApplicationContext(),"Ad Loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed(){requestNewInterstitial();}
});
//Load Ad Starts
AdView mAdView=(AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//Load Ad Stops
}
public void second(View view){
Intent i = new Intent(getApplicationContext(), second.class);
startActivity(i);
}
public void ShowAd(){
if(mInterstitialAd.isLoaded()){
Toast.makeText(getApplication(), "The Ad has Loaded.", Toast.LENGTH_SHORT).show();
mInterstitialAd.show();
}
else
Toast.makeText(getApplication(), "The Ad has not loaded yet.", Toast.LENGTH_SHORT).show();
}
public void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
我的问题是它总是显示 toast "Ad failed to Load"。我不知道我的代码中缺少什么。请帮忙!!。我已经对此进行了很多搜索,所以请不要 post 链接到其他问题。
清单
<?xml version="1.0" encoding="utf-8"?>
<!-- Include required permissions for Google Mobile Ads to run -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<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>
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name=".second"
android:label="@string/title_activity_second"></activity>
<activity
android:name=".third"
android:label="@string/title_activity_third"></activity>
</application>
LogCat
Logcat 清楚地说:
06-01 00:59:20.883 16251-16326/abc.myapplication I/Ads﹕ No fill from ad server.
这就是您没有收到任何广告的原因。此时、地点和设备有 none 可供您使用。如果你想测试你需要设置测试 adUnitId。这也由 logcat:
给出06-01 00:59:20.159 16251-16251/abc.myapplication I/Ads﹕ Use AdRequest.Builder.addTestDevice("1CC3C3CDC4D015059D600FE0D095EAE5") to get test ads on this device.