Thursday, April 23, 2015

Android Admob 예제 다운로드

 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

package com.example.admobsample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.LinearLayout;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class MainActivity extends Activity {
 private AdView adView;
 private final String MY_AD_UNIT_ID = "a151b9ce1aabeef";

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // adView 만들기
  adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
  LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);

  // 찾은 LinearLayout에 adView를 추가
  layout.addView(adView);

  // 기본 요청을 시작하여 광고와 함께 요청을 로드
  adView.loadAd(new AdRequest());
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }
}

다운로드

No comments:

Post a Comment