间质性添加是没有得到在机器人装 [英] Interstitial Add is not getting loaded in android

查看:124
本文介绍了间质性添加是没有得到在机器人装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试我发现我的 onLoaded()返回的是假的,只有一个空白的白色屏幕后。 没有附加组件是越来越装!即使我等待无限时间 外接设备ID是从采摘

After debugging i found out that my onLoaded() return is false and only a blank white screen appears. No add is getting loaded! even if i wait for infinite time the add unit id is picked from

https://developers.google.com/mobile-广告-SDK /文档/ AdMob的/安卓/间质性  (样品加) 这是我的MainActivity类

https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial (for sample add) Here is my MainActivity class

    package com.example.jatinarora.threestickhockey;
    import android.app.ActionBar;
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.media.MediaPlayer;
    import android.os.SystemClock;
    import android.support.v4.view.MotionEventCompat;
    import android.support.v4.view.VelocityTrackerCompat;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.MotionEvent;
    import android.view.VelocityTracker;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.view.WindowManager;
    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 ActionBarActivity {

public InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    requestNewInterstitial();
    float count123 = 1 ;
    // i tried setting the loop to infinity to wait for the advertisment to load!
    while(count123 >=0) {
        if (interstitial!= null && interstitial.isLoaded()) {
            interstitial.show();
            count123 = -1;
        }
        }
        }

private void requestNewInterstitial() {
    AdRequest adRequest = new AdRequest.Builder().build();
    interstitial.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.menu_main, menu);
    return true;
}
@Override
protected void onResume() {
    super.onResume();
    mView.running = true;
}
protected void onPause()
{
    mView.resume = 1;
    mView.running = false;
    super.onPause();
}

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

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}}

在我的 activity_main.xml 我没加AD浏览报,因为在所有的教程和联系我去过,我还没有看到任何的间隙,它被用来横幅

In my activity_main.xml I didn't add AdView because in all the tutorials and links i have visited,I haven't seen any for interstitial , It was used for banner

下面是我的activity_main.xml

Here is my activity_main.xml

    <RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:label="@string/app_name"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp" tools:context=".MainActivity">
<com.example.jatinarora.threestickhockey.mView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
   </RelativeLayout>

下面是我的manifestFile

Here is my manifestFile

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.jatinarora.threestickhockey" >
    <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/Theme.AppCompat.Light.NoActionBar">
        <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
    <activity android:name="com.google.android.gms.ads.AdActivity"
               android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
  </application>
</manifest>

任何建议,错误为什么添加没有显示出来,或任何替代的解决方案将有助于很多!

Any suggestion ,mistake why the add is not showing up or any alternate solution will be helpful a lot!

推荐答案

[问题的原因]

我不能给一个precise原因的问题,但是,在主线程中运行循环引入滞后,这就是为什么加不加载,因为超时如此之快,也没有理由房间吧,因为你有很多方法在该线程占用的工作,这也可能是白色的屏幕上3-4秒钟的原因。但除此之外,在加没有出现在一般可达大概可能是您的网络连接或.......

i can't give a precise reason to the problem, but, Running loops on the main thread introduces lags, and that is the reason why the add is not loading because it times out so fast and there is no room for it,cause you got alot of process hogging work on that thread, that might also be the reason for the white screen for 3-4 seconds .. but aside from that, the add not showing up in general probably might be your internet connection or .......

让先生,忘了循环,检查此<一个href="http://stackoverflow.com/questions/27672035/is-there-a-way-to-cancel-or-stop-an-interstital-ad-if-the-app-is-not-in-foregr/27672376#27672376">answer ,它西港岛线告诉你如何显示附加时,它的完成。loading - 它 onAdLoaded()被触发时, interstitial.isLoaded()是不是循环的这一切你留给互联网和谷歌的时候..剩下的真实,外接会出现,当它出现时,你可以添加断点知道它是如何下来

so Sir, forget about the loop, check this answer , it wil show you how to show the add when it's done loading - it has onAdLoaded() which is triggered when interstitial.isLoaded() is true, instead of looping for it all the time.. and the rest you leave it to internet and google, the add will show up when it shows up, you can add breakpoint to know how it gets down

这篇关于间质性添加是没有得到在机器人装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆