Home » Android » Unity ads not showing ads

Unity ads not showing ads

Posted by: admin November 1, 2017 Leave a comment

Questions:

Today I was integrate unity ads on my android project and I am following same integration techniques that is given on unity ads documentation section. But Unity ads not showing, I think my coding is incorrect or incomplete. Please help me to integrate.

My MainActivity.java

package in.unity_ads.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;

import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;

public class MainActivity extends AppCompatActivity {

final private UnityAdsListener unityAdsListener = new UnityAdsListener();
public int coins;

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

@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;
}

public void buttonOnClick(View v) {
    Button mButton = (Button) findViewById(R.id.button);
    if(UnityAds.isReady("rewardedVideo")){
        UnityAds.show(this, "rewardedVideo");
    }else{
        mButton.setText("Initializing");
        UnityAds.initialize(this, "1091553", unityAdsListener);
    }
}

public void rewardPlayer() {
    TextView mTextView = (TextView) findViewById(R.id.textView);
    coins = coins + 10;
    mTextView.setText("Coins: " + Integer.toString(coins));
}

private class UnityAdsListener implements IUnityAdsListener {
    @Override
    public void onUnityAdsReady(String s) {
        final Button mButton = (Button) findViewById(R.id.button);
        mButton.setText("Show Ad");
    }

    @Override
    public void onUnityAdsStart(String s) {

    }

    @Override
    public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
        if (finishState != UnityAds.FinishState.SKIPPED) {
            rewardPlayer();
        }
    }
    @Override
    public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {


     }
    }
}

My Manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.unity_ads.test">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:screenOrientation="landscape">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <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" />
</application>

and finally Please help! how to add .AAR file on android libary.

Help me to resolves this problem!

Answers: