Mopub Banner广告没有出现

时间:2018-04-14 04:51:47

标签: android ads mopub banner-ads

我是Android编程中的新手,所以我只想在我的应用中显示Mopub横幅广告。我创建了Sample应用程序,还在Mopub中创建了广告单元ID。

我已成功整合SDK并按照此页面上的https://developers.mopub.com/docs/android/banner/说明操作。

但我不知道为什么我的应用程序是Live-G-play只发送请求但没有印象。我还检查了我的手机和电话这是真的。没有广告在显示。这是我的代码

有人可以帮帮我吗?

mainactivity.java: -

import com.mopub.mobileads.MoPubErrorCode;
import com.mopub.mobileads.MoPubView;
import static com.mopub.mobileads.MoPubView.BannerAdListener;

public class MainActivity extends AppCompatActivity implements BannerAdListener {  
private MoPubView mBanner;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBanner = (MoPubView) findViewById(R.id.bannerview);
    mBanner.setAdUnitId("XXXXXXXXXXXXXXXXXXXXXXXX"); // Enter your Ad Unit ID from www.mopub.com
    mBanner.setBannerAdListener(this);
    mBanner.loadAd();



}

@Override
protected void onDestroy() {
    mBanner.destroy();
    super.onDestroy();
}

@Override
public void onBannerLoaded(MoPubView banner) {
     Log.d("MoPub Demo", "Banner loaded callback.");
}

@Override
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
    Log.d("MoPub Demo", "Banner failed callback with: " + errorCode.toString());
}

@Override
public void onBannerClicked(MoPubView banner) {
    Log.d("MoPub Demo", "Banner clicked callback.");
}

@Override
public void onBannerExpanded(MoPubView banner) {
    Log.d("MoPub Demo", "Banner expanded callback.");
}

@Override
public void onBannerCollapsed(MoPubView banner) {
    Log.d("MoPub Demo", "Banner collapsed callback.");
}
}

activity_main.xml中: -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.mopub.mobileads.MoPubView
    android:id="@+id/bannerview"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    />


</RelativeLayout>

的build.gradle(module.app): -

repositories {
      // ... other project repositories
         jcenter() // includes the MoPub SDK and AVID library
            maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
         }
apply plugin: 'com.android.application'


android {
      compileSdkVersion 27
       defaultConfig {
    applicationId "com.your.prject.appmopubtest"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation('com.mopub:mopub-sdk:4.20.0@aar') {
    transitive = true
}
}

的build.gradle(project.appmopubtest): -

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()
    maven { url "https://s3.amazonaws.com/moat-sdk-builds" }

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

的AndroidManifest.xml: -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.your.prject.appmopubtest">
<!-- Required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Optional permissions. Will pass Lat/Lon values when available. Choose either Coarse or Fine -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <!-- All ad formats -->
        <activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>

    <!-- Interstitials -->
    <activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
    <activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

    <!-- Rewarded Video and Rewarded Playables -->
    <activity android:name="com.mopub.mobileads.RewardedMraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

    <activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

</application>

</manifest>

0 个答案:

没有答案