Reputation: 657
I'm in the later stages of my app and am wondering how I should get an Inneractive ad to work. I've tried their tutorial and it is not displaying ads despite the fact that my connection is a perfect 6 bars on my Galaxy S II. I have both the inneractive and the support jar in referenced libraries. Here is the code I am using:
package com.ads;
import com.inneractive.api.ads.InneractiveAd;
import java.util.Hashtable;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class AdsActivity extends Activity {
LinearLayout linear;
Button interstitialBtn;
Hashtable<InneractiveAd.IaOptionalParams, String> metaData = new Hashtable<InneractiveAd.IaOptionalParams, String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Optional parameters
metaData.put(InneractiveAd.IaOptionalParams.Key_Gender, "F");
metaData.put(InneractiveAd.IaOptionalParams.Key_Keywords, "sports,fashion");
// Receive inneractive ad events
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("InneractiveAd"));
linear = new LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
// Interstitial ad button
interstitialBtn = new Button(this);
interstitialBtn.setText("Interstitial ad");
interstitialBtn.setWidth(getWindowManager().getDefaultDisplay().getWidth());
interstitialBtn.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// Display interstitial ad
if (!InneractiveAd.displayAd(AdsActivity.this, linear, "Android_IA_Test", InneractiveAd.IaAdType.Interstitial, 0, AdsActivity.this.metaData))
noConnectivity();
}
});
// Display banner ad
if (!InneractiveAd.displayAd(AdsActivity.this, linear, "Android_IA_Test", InneractiveAd.IaAdType.Banner, 120, AdsActivity.this.metaData))
noConnectivity();
linear.addView(interstitialBtn);
setContentView(linear);
}
public void noConnectivity() {
AlertDialog alertDialog = new AlertDialog.Builder(AdsActivity.this).create();
alertDialog.setTitle("This application is free but requires an internet connection");
alertDialog.setMessage("Please configure your connectivity settings and re-try");
alertDialog.setButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
onBackPressed();
} });
alertDialog.show();
}
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
/* Receive the inneractive ad event. Can be one of the following events -
* IaAdReceived - Called when a new paid Ad has been received and is about to be displayed.
* IaDefaultAdReceived - Called when a new default Ad has been received and is about to be displayed.
* IaAdFailed - Called when an Ad request fails to get an Ad.
* IaAdClicked - Called when an Ad clicked.
* IaAdResize - Called when an Ad resized.
* IaAdResizeClosed - Called when an Ad resize closed.
* IaAdExpand - Called when an Ad expanded.
* IaAdExpandClosed - Called when an Ad expand closed.
*/
String message = intent.getStringExtra("message");
}
};
@Override
protected void onDestroy() {
// Unregister events since the activity is about to be closed.
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
super.onDestroy();
}
}
Any help would be greatly appreciated.
Upvotes: 0
Views: 1708
Reputation: 13562
I have not really worked with the Ad Provider you have mentioned but I have worked with another. Here are a few things you could do.
Check to see that you are getting a success/failure in receiving the ad. Usually they have their listeners which u can use.
Also try making an empty layout in xml and put your ad in it, rather than doing it on the fly programatically.
If they have their own activity in which you can display the ad, try it first.
One more thing. Do a setContentView() first and then add the ad. Try it once with the way u r doing. Make the linearlayout, setcontentview and then addview(). If that doesnt work try the xml method.
Upvotes: 3