2016-07-13 2 views
2

내 활동 중 하나에서 기본 앱 설치 광고보기를 표시하는 데 문제가 있습니다. Google은 기본 광고 구현을 다음과 같이 표시하므로 https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/NativeExample 나는 내 프로젝트에 코드를 통합했습니다. 여기 내 Gradle을 파일입니다Android NativeAppInstallAdView에 광고가 표시되지 않습니다

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "com.somepack.tests" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 

    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    compile 'com.android.support:recyclerview-v7:23.4.0' 
    compile 'com.android.support:cardview-v7:23.4.0' 
    compile 'com.google.android.gms:play-services-ads:9.2.0' 
    compile 'com.google.firebase:firebase-ads:9.0.0' 
} 

apply plugin: 'com.google.gms.google-services' 

그리고 나는 또한 내 루트 Gradle을 파일에 동일한 코드를 추가 한 : 나는 구글의 앱 ID 및 장치 ID를 사용하여 응용 프로그램을 실행하는 것을 시도했다

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     mavenLocal() 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
     classpath 'com.google.gms:google-services:3.0.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     mavenLocal() 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

하고, 모든 작동하는 것 같습니다. 나는 그것이 아무튼 생각

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.FrameLayout; 
import android.widget.ImageView; 
import android.widget.RatingBar; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.google.android.gms.ads.AdListener; 
import com.google.android.gms.ads.AdLoader; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.MobileAds; 
import com.google.android.gms.ads.formats.NativeAd; 
import com.google.android.gms.ads.formats.NativeAppInstallAd; 
import com.google.android.gms.ads.formats.NativeAppInstallAdView; 

import java.util.List; 

public class AdActivity extends AppCompatActivity { 

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

     String ADMOB_APP_ID = getString(R.string.admob_app_id); 
     // Initialize the Mobile Ads SDK. 
     MobileAds.initialize(this, ADMOB_APP_ID); 
     refreshAd(); 
    } 

    private AdRequest.Builder getBuilder() { 
     AdRequest.Builder builder = new AdRequest.Builder(); 
     if (BuildConfig.DEBUG) { 
      builder.addTestDevice("BDFA4B1F1E11FDA72D43368841CF0E04"); 
     } 
     return builder; 
    } 

    private void refreshAd() { 
     AdLoader.Builder builder = new AdLoader.Builder(this, getString(R.string.admob_unit_id)); 
     builder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() { 
      @Override 
      public void onAppInstallAdLoaded(NativeAppInstallAd ad) { 
       FrameLayout frameLayout = 
         (FrameLayout) findViewById(R.id.fl_adplaceholder); 
       NativeAppInstallAdView adView = (NativeAppInstallAdView) getLayoutInflater() 
         .inflate(R.layout.ad_app_install, null); 
       populateAppInstallAdView(ad, adView); 
       frameLayout.removeAllViews(); 
       frameLayout.addView(adView); 
      } 
     }); 

     AdLoader adLoader = builder.withAdListener(new AdListener() { 
      @Override 
      public void onAdFailedToLoad(int errorCode) { 
       Toast.makeText(AdActivity.this, "Failed to load native ad: " 
         + errorCode, Toast.LENGTH_SHORT).show(); 
      } 
     }).build(); 

     adLoader.loadAd(getBuilder().build()); 
    } 

    private void populateAppInstallAdView(NativeAppInstallAd nativeAppInstallAd, 
              NativeAppInstallAdView adView) { 
     adView.setHeadlineView(adView.findViewById(R.id.appinstall_headline)); 
     adView.setImageView(adView.findViewById(R.id.appinstall_image)); 
     adView.setBodyView(adView.findViewById(R.id.appinstall_body)); 
     adView.setCallToActionView(adView.findViewById(R.id.appinstall_call_to_action)); 
     adView.setIconView(adView.findViewById(R.id.appinstall_app_icon)); 
     adView.setPriceView(adView.findViewById(R.id.appinstall_price)); 
     adView.setStarRatingView(adView.findViewById(R.id.appinstall_stars)); 
     adView.setStoreView(adView.findViewById(R.id.appinstall_store)); 

     // Some assets are guaranteed to be in every NativeAppInstallAd. 
     ((TextView) adView.getHeadlineView()).setText(nativeAppInstallAd.getHeadline()); 
     ((TextView) adView.getBodyView()).setText(nativeAppInstallAd.getBody()); 
     ((Button) adView.getCallToActionView()).setText(nativeAppInstallAd.getCallToAction()); 
     ((ImageView) adView.getIconView()).setImageDrawable(nativeAppInstallAd.getIcon() 
       .getDrawable()); 

     List<NativeAd.Image> images = nativeAppInstallAd.getImages(); 

     if (images.size() > 0) { 
      ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable()); 
     } 

     // Some aren't guaranteed, however, and should be checked. 
     if (nativeAppInstallAd.getPrice() == null) { 
      adView.getPriceView().setVisibility(View.INVISIBLE); 
     } else { 
      adView.getPriceView().setVisibility(View.VISIBLE); 
      ((TextView) adView.getPriceView()).setText(nativeAppInstallAd.getPrice()); 
     } 

     if (nativeAppInstallAd.getStore() == null) { 
      adView.getStoreView().setVisibility(View.INVISIBLE); 
     } else { 
      adView.getStoreView().setVisibility(View.VISIBLE); 
      ((TextView) adView.getStoreView()).setText(nativeAppInstallAd.getStore()); 
     } 

     if (nativeAppInstallAd.getStarRating() == null) { 
      adView.getStarRatingView().setVisibility(View.INVISIBLE); 
     } else { 
      ((RatingBar) adView.getStarRatingView()) 
        .setRating(nativeAppInstallAd.getStarRating().floatValue()); 
      adView.getStarRatingView().setVisibility(View.VISIBLE); 
     } 

     // Assign native ad object to the native view. 
     adView.setNativeAd(nativeAppInstallAd); 
    } 
} 

: 내 값으로 앱 ID 및 장치 ID를 변경하면, 그냥 오류 코드 여기에 0

과 함께 '기본 광고를로드하지 못했습니다합니다'유지 나의 활동 내 APK가 디버그되어 릴리스로 시도했기 때문에 광고를 표시하지 않습니다. 그러나 기회는 없습니다. AdMob 패널 또는 구현해야하는 코드에 대한 설정이 누락 되었습니까? 나는 어떤 도움을 위해 크게 appriciated입니다.

P.S : 위 코드는 단지 시험판이며 Play 스토어에있는 실제 앱에는 동일한 코드가 있지만 성공하지 못했습니다.

답변

0

네이티브 고급 광고를 게재 할 수없는 광고 단위에서 요청할 가능성이 있습니다. AdMob의 네이티브 광고 고급에 대해 귀하와 귀하의 앱이 베타 버전으로 승인 되었습니까? 그렇지 않으면 위에 제공된 기본 코드가 테스트 모드에서만 작동한다는 것을 의미하는 기본 고급 광고 단위를 만들 수 없습니다.

AdMob은 두 가지 종류의 네이티브 광고 인 고급 및 익스프레스 (a guide that explains the difference)를 제공합니다. 이봐

+0

: 기본 Express는 새로운 쉽게 모든 AdMob 게시자에게 열려 있습니다, 그래서 당신은 아직 그것을 시도하지 않은 경우, 나는 그것을 봐주는 게 좋을 것 @ RedBrogdon, 귀하의 의견에 감사드립니다. 나는 네이티브 익스프레스와 어드밴스드 광고를 동일한 키로 시도했지만, 작동시키지 못했습니다. –

+1

그런 경우 AdMob SDK 포럼에 게시하는 것이 좋습니다. 지원 담당자가 더 자세한 정보를 얻고 진행 상황을 볼 수 있습니다. https://groups.google.com/forum/#!categories/google-admob-ads-sdk/android – RedBrogdon

+0

감사합니다. @ RedBrogdon, 포럼까지 가자. –

관련 문제