我正处于应用的后期阶段,我想知道如何才能获得Inneractive广告。我已经尝试了他们的教程并且它没有显示广告,尽管我的连接是我的Galaxy S II上的完美6条。我在引用的库中都有inneractive和support jar。这是我正在使用的代码:
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();
}
}
非常感谢任何帮助。
答案 0 :(得分:3)
我没有真正使用您提到过的广告提供商,但我与其他广告提供商合作过。以下是您可以做的一些事情。
检查您是否在接收广告时获得成功/失败。通常他们有他们可以使用的听众。
还尝试在xml中制作一个空布局并将广告放入其中,而不是以编程方式即时执行。
如果他们有自己的活动可以展示广告,请先试试。
还有一件事。首先执行setContentView(),然后添加广告。用你的方式尝试一次。进行linearlayout,setcontentview,然后addview()。如果这不起作用,请尝试使用xml方法。