그래서 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 (메뉴)를 정의한다 얻을.
adView.setAdSize(AdSize.BANNER); the Method setAdSize is undefined for the type AdView
그리고 adView.loadAd(adRequest);
은 형에서 AdView의 방법 load.ad (되는 AdRequest)는 작동하지 않습니다 여전히 가이드에 말했듯이 나는 https://developers.google.com/mobile-ads-sdk/docs/?hl=en_US를 추가 인수 (되는 AdRequest)
적용되지 않습니다합니다. http://prntscr.com/2o6vo4
을 추가하므로 java 파일에서이 xml add 요소를 참조해야합니까? @Deeepak Jangir –
이것을 레이아웃 XML 파일에 추가하기 만하면됩니다. –
Google Play 서비스의 구현이 다르며 –