Im wondering whats the best way to integrate ads into Unity Android, as Unity outputs apk files directly, there seems to be no way to use admobs native java sdk.
Admob doesn’t seem to have custom API for me to call…
so I guess I’m left with reversing their sdk and replicating it in Unity/C#?
Before I start doing this, has anyone solved this or have any other recommendations?
includes an example of how to access Admob and Quattro Wireless (but ignore the QW as they no longer support Android). It uses the java plugin feature to override the normal UnityPlayerActivity (Unity’s Java code for Android) to add a banner on top of the GL screen. Please read the code as this is no fire-and-forget solution for ads to magically appear in your apps. Also, it has been reported that there are mac/windows incompatibilities with the build script, so might need some changes if you’re on mac.
Does anyone have any information on compiling this on Mac? When I try to rebuild with my changes it can’t find the Admob and Quattro .jar/classes no matter how I include their paths in the .sh file (which I’m dragging and dropping onto the Terminal window). Any clues?
Just in case anyone was wondering, I got it to work by changing the classpath from a quoted semi-colon delimited list to a non-quoted colon delimited list of classes to include.
I added 2 jar files to lib directory of eclipse project
(1)Applications/Unity right-clicked and Show Package Content-> /Contents/PlaybackEngines/AndroidPlayer/bin/classes.jar
(2)GoogleAdMobAdsSdk-X.X.X.jar
AdMobTestActivity.java
package org.example.AdMobTest;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.unity3d.player.*;
import com.google.ads.AdView;
import com.google.ads.AdSize;
import com.google.ads.AdRequest;
public class AdMobTestActivity extends UnityPlayerActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupAds();
}
private void setupAds() {
// And this is the same, but done programmatically
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
AdView adView = new AdView(this, AdSize.BANNER, "ADMOB_ID");
layout.addView(adView, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
adView.loadAd(new AdRequest());
}
}