2013-03-14 4 views
4

내 앱에 Google 광고를 추가하려고합니다 (이번이 처음입니다). jar 파일도 추가했습니다.Google 광고를 Android 앱에 추가

다음은 xml입니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/headerbgcolor" 
     android:weightSum="1" > 

     <Button 
      android:id="@+id/back" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:text="@string/back" 
      android:onClick="finishActivity"/> 

     <TextView 
      android:id="@+id/headertitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="0.6" 
      android:gravity="center" 
      android:text="@string/header_title" /> 

     <Button 
      android:id="@+id/home" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:text="@string/home" /> 
    </LinearLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="wrap_content" 
     android:layout_height="320dp" 
     android:scrollbarAlwaysDrawVerticalTrack="true" > 
    </ListView> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 


     <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="a14f26e5d930307" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="AVD_for_4in_WVGA_Nexus_S,5554" /> 



    </RelativeLayout> 

</LinearLayout> 

하지만 클래스에서 정의하려고 할 때 내 클래스에서 adview를 정의 할 수 없습니다.

여기 내 수업을 정의하려고합니다.

public class Cities extends Activity { 

    Button btnback = null; 
    Button btnhome = null; 
    TextView headertitle = null; 
    ListView lstcities; 
    ImageView imgfooter; 
    AdView adView; 
    public String BtnSelected; 

내가

AdView adview; 

poblem은 무엇인가를 정의하기 위해 노력하고있을 때 내가, 입력 해결할 수없는 오류로 AdView는 무엇입니까? GoogleAdMobAdsSdk-4.0.4.jar

당신이 난 그냥이

<LinearLayout 
    android:id="@+id/imgBanner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" /> 

를 작성한 XML에서이 라인을

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


     AdView adView = new AdView(this, AdSize.BANNER, 
        getString(R.string.publisherID)); 


     LinearLayout layout = (LinearLayout) findViewById(R.id.imgBanner); 
     layout.addView(adView); 

     AdRequest adRequest = new AdRequest(); 
     adRequest.setTesting(true); 
     // Start loading the ad in the background. 
     adView.loadAd(adRequest); 

수입이 -

+0

수입을 확인하셨습니까? – njzk2

+0

@ njzk2 이클립스를 사용하고 있습니다. 필요한 패키지를 자동으로 가져옵니다. 하지만 google.ads 패키지를 가져올 수 없습니다. – Beginner

답변

5

나는이 jar 파일을 사용하고 있습니다 매니페스트 파일

<activity 
    android:name="com.google.ads.AdActivity" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode" > 
</activity> 
+0

해당 클래스를 가져올 수 없습니다. 나는 또한 질문을 게시하기 전에 시도했다 – Beginner

+0

어떤 googleads 버전을 사용 했습니까? – Nirali

+0

방금 ​​Google에서 다운로드했습니다. 나는 어떤 버전을 얻지 못했습니까? – Beginner

관련 문제