问题
I am trying to implement InMobi ads, but ads do not show up.
I have followed the tutorial here : http://www.inmobi.com/support/integration/23817448/22051163/android-sdk-integration-guide/
This is my code;
interstitial = new IMInterstitial(this, "my_property_id");
interstitial.loadInterstitial();
if (interstitial.getState() ==IMInterstitial.State.READY)
interstitial.show();
interstitial.setIMInterstitialListener(new IMInterstitialListener() {
public void onShowInterstitialScreen(IMInterstitial arg0) {
}
@Override
public void onLeaveApplication(IMInterstitial arg0) {
}
@Override
public void onDismissInterstitialScreen(IMInterstitial arg0) {
}
@Override
public void onInterstitialLoaded(IMInterstitial arg0) {
}
@Override
public void onInterstitialInteraction(IMInterstitial interstitial, Map<String, String> params) {
}
@Override
public void onInterstitialFailed(IMInterstitial arg0, IMErrorCode arg1) {
}
});
What am i missing?
回答1:
Although, this is a pretty late reply, I hope it helps you. First thing is to define necessary permissions and activities to manifest. For referrer tracking, you must add:
<receiver
android:name="com.inmobi.commons.analytics.androidsdk.IMAdTrackerReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
You must also add InMobi activity to your manifest:
<activity
android:name="com.inmobi.androidsdk.IMBrowserActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:hardwareAccelerated="true" />
In the java part, first you have to initialize InMobi. This is generally done in launcher activity. If you haven't initialized, this was the first thing missing in your code. The second thing was the missing listener. The class for interstitial ad should be sth like this:
public class InterstitialAdActivity extends Activity implements IMInterstitialListener {
protected IMInterstitial mIMInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
InMobi.initialize(this, "ID");
mIMInterstitialAd = new IMInterstitial(this, "ID");
mIMInterstitialAd.setIMInterstitialListener(this);
mIMInterstitialAd.loadInterstitial();
}
@Override
public void onDismissInterstitialScreen(IMInterstitial arg0) {
// TODO Auto-generated method stub
}
@Override
public void onInterstitialFailed(IMInterstitial arg0, IMErrorCode arg1) {
// TODO Auto-generated method stub
}
@Override
public void onInterstitialInteraction(IMInterstitial arg0,
Map<String, String> arg1) {
// TODO Auto-generated method stub
}
@Override
public void onInterstitialLoaded(IMInterstitial arg0) {
if(mIMInterstitialAd.getState() == State.READY)
mIMInterstitialAd.show();
}
@Override
public void onLeaveApplication(IMInterstitial arg0) {
// TODO Auto-generated method stub
}
@Override
public void onShowInterstitialScreen(IMInterstitial arg0) {
// TODO Auto-generated method stub
}
}
回答2:
No issues with it, they take time to appear in your app. Just give it some time.
来源:https://stackoverflow.com/questions/20160497/inmobi-ads-does-not-show-up-on-android