我正在将 AdMob 合并到我的应用程序中。我已按照开发人员页面中的步骤进行操作。然而 AdRequest.Builder() 带有红色下划线,它表示:
AdRequest 无法解析为类型
and
AdRequest.Builder 无法解析为类型。
可能是什么问题呢?
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class FireRoomActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_room);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
在 xml 中我已经这样显示了 admob:
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
你的代码是混合的Admob SDK(Google Play) https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play and Android(6.4.1 及更早版本的 SDK) https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#android
Use
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
AdRequest adRequest = new AdRequest.Builder().build();
and
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
如果您使用 Admob SDK (Google Play)
Or use
import com.google.ads.AdRequest;
import com.google.ads.AdView;
AdRequest adRequest = new AdRequest();
and
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
如果你使用早期的SDK
对于 Admob SDK (Google Play),不要忘记更改命名空间
xmlns:ads="http://schemas.android.com/apk/res-auto"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)