노력과 삽질 퇴적물

안드로이드: 구글 애드몹 본문

프로그래밍note/언어. JAVA & JDK 계열

안드로이드: 구글 애드몹

MTG 2014. 11. 21. 16:34


* 해당 포스트는 adMobSDK.jar없이 최신 '구글 플레이 라이브러리'로 구글 애드몹(google adMob)을 구현한 예제입니다.






0. 필요한 파일


파일명

예시 경로

 이클립스 [#]

 C:\eclipse
 (Kepler, Luna. 2가지로 테스트 해본결과 상관은 없습니다.)

 ADT [#]

 C:\android-sdk-windows


* JDK 1.6rhk 1.7으로도 정상작동하는거 확인했습니다.






구글 [#애드몹, 한국어 페이지]








2. 이큽립스 세팅


Android SDK Manager를 통해

Android SDK Build-tools와 Google Play services를 아래와 같이 최신버전으로 맞춰줍니다.


!!!주의사항!!!

General>Existing Projects into Workspace가 아니고

Android>Existing Android Code Into Workspace입니다.

경로: C:\android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib






3. XML


① Manifest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.analoggreen.testadmob"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:theme="@android:style/Theme.Translucent"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
 
        <activity
            android:name="MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>


② 레이아웃 XML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#000000">

      <com.google.android.gms.ads.AdView
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:id="@+id/adView"
          ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx"
          ads:adSize="BANNER"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"/>
</LinearLayout>






4. JAVA


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.example.testadmob;
 
import android.app.Activity;
import android.os.Bundle;

mport android.provider.Settings.Secure;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
 
public class MainActivity extends Activity
{
    private AdView adView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     //String deviceid = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
     AdRequest adRequest = new AdRequest.Builder().addTestDevice(deviceid).build();
        adView = (AdView) this.findViewById(R.id.adView);
        adView.loadAd(adRequest);
    }
 
    @Override
    public void onResume()
    {
        super.onResume();
        if (adView != null)    {    adView.resume();    }
    }
 
    @Override
    public void onPause()
    {
        super.onPause();
        if (adView != null)    {    adView.pause();    }
    }
 
    @Override
    public void onDestroy()
    {
        super.onDestroy();
        if (adView != null)    {    adView.destroy();    }
    }
}
 






기타. 참조자료


시작하기 - Google Mobile Ads SDK — Google Developers

Google Play 서비스 이전 - Google Mobile Ads SDK — Google Developers

도라지 - Dorage: [Unity] [배너/전면] 새로운 AdMob 광고 달기

전면광고 적용 가이드 - 애드몹 100% 즐기기


애드몹 광고 내앱에 추가 방법 - Google Play의 Android 앱


Banner Ad - AdMob Android Guides — Google Developers

Could not find class 'com.google.android.gms.ads.AdView'... - Google 그룹스

eclipse - how to get an android device ID - Stack Overflow






기타. 변경이력


일자

변경이력

2014-11-21

 초안.

2014-11-26

 4. JAVA. 테스트용 디바이스 아이디 관련 추가