1

I am kind of newbie in Android Programming, So I Just want to Display Mopub banner ad in my app. I created the Sample app, also created Ad unit id in Mopub.

I successfully integrated SDK and following their https://developers.mopub.com/docs/android/banner/ instructions on this page.

but I don't know why my app which is Live on G-play Only sending the request but no impression. I also checked on my Phone & its true. No ads are displaying. Here is My Code

Can anyone Help me Please?

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>

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105

0 Answers0