所以我按照 admob 和 Google Play 服务的指南进行操作,https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play我遇到了一个问题。
他们在网站上提供的代码不起作用。我收到错误。
package puske.com;
import com.google.android.gms.ads.*;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
public class Menu extends Activity {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
// Create the adView.
adView = new AdView(this);
adView.setAdUnitId(MY_AD_UNIT_ID);
adView.setAdSize(AdSize.BANNER);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout".
RelativeLayout layout = (RelativeLayout)findViewById(R.id.menuz);
// Add the adView to it.
layout.addView(adView);
// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder().build();
// Load the adView with the ad request.
adView.loadAd(adRequest);
我收到错误adView = new AdView(this);
构造函数 AdView(Menu) 未定义。
adView.setAdSize(AdSize.BANNER); the Method setAdSize is undefined for the type AdView
And adView.loadAd(adRequest);
AdView 类型中的方法 load.ad(adRequest) 不适用于参数 (AdRequest)
I added https://developers.google.com/mobile-ads-sdk/docs/?hl=en_US正如指南中所说,仍然不起作用。http://prntscr.com/2o6vo4
您可以使用布局来显示您的添加。只需将以下代码放入您的布局中您想要在屏幕上显示的位置即可。
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="Your AddMob ID"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE" />
</RelativeLayout>
您的 libs 文件夹中应该有最新的 GoogleAdmobSdk.jar。
这对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)