androidinmobi

InMobiBanner is not initialized


I am getting this error while integrating InMobi Banner ad.

InMobiBanner is not initialized. Ignoring InMobiBanner.load()

I am using version 7.0.4 of InMobi Ads SDK. I have followed the instructions given in the documentation.

How can I fix this problem? Please help me regarding this.


Solution

  • Finally, I got the solution. Somehow, InMobiBanner is not working if the placement id is given in XML layout. So, we have to initialize the InMobiBanner programmatically with the Java code.

    But complete your profile information and add your payment information before integrating the InMobi SDK. Also, don't create any placements before that.

    Step 1:

    Initialize the InMobiSdk in your Application file with the below code:

    public class MyApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            InMobiSdk.init(this, "Your Account ID");
            InMobiSdk.setLogLevel(InMobiSdk.LogLevel.DEBUG);
        }
    
    }
    

    Step 2:

    Add the Application file in your Manifest file and also make the hardwareAccelerated attribute of application tag to true. Check the sample code given below:

    <application
        android:name=".MyApplication"
        android:hardwareAccelerated="true"
        ..
    
        <activity
            android:name="com.inmobi.rendering.InMobiAdActivity"
            android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
            android:resizeableActivity="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.NoTitleBar"
            tools:ignore="UnusedAttribute" />
    
    </application
    

    Step 3:

    Add a ViewGroup in your layout so that we can add the InMobiBanner view within that view.

    <RelativeLayout
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center" />
    

    Step 4:

    Now add the below Java code in your Activity or Fragment to initialize and load the InMobiBanner ad.

    InMobiBanner bannerAd = new InMobiBanner(this, 1234567890L);
    RelativeLayout adContainer = findViewById(R.id.banner);
    float density = getResources().getDisplayMetrics().density;
    RelativeLayout.LayoutParams bannerLp = new RelativeLayout.LayoutParams((int) (320 * density), (int) (50 * density));
    adContainer.addView(bannerAd, bannerLp);
    bannerAd.load();
    

    Hope this helps.