2015-05-22 40 views
1

這是我第一次爲我的android應用實施插頁式廣告。我在整合方面遇到問題,我遵循官方的Google移動廣告SDK教程,但我仍然不明白的是如何準備初始版本?我只是想設置廣告並將其上傳到商店。無法爲Google Play發佈整合admob插頁式廣告

是否有一些錯誤或我有過誤解?廣告甚至沒有出現。

interstitial = new InterstitialAd(this); 
     interstitial.setAdUnitId("myunitid"); 

     AdRequest adRequest = new AdRequest.Builder().build(); 

     interstitial.loadAd(adRequest); 
     displayInterstitial(); 

} 

public void displayInterstitial() { 
     if (interstitial.isLoaded()) { 
      interstitial.show(); 
     } 
    } 

這是清單文件

<meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version" /> 
      <!-- Activity required to show ad overlays. --> 
      <activity 
       android:name="com.google.android.gms.ads.AdActivity" 
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

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

的部分原因是它是什麼,我的gradle這個

compile 'com.android.support:support-v4:22.1.1' 
    compile 'com.google.android.gms:play-services:7.3.0' 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
+0

發佈您的清單文件 –

+0

我已經從我的清單和gradle中添加了額外的代碼。 – user3264924

回答

0

Android Studio中的EclipseØ?

Android的工作室:

添加依賴

dependencies { 
     compile fileTree(dir: 'libs', include: ['*.jar']) 
     compile 'com.android.support:appcompat-v7:21.0.0' 
     compile 'com.google.android.gms:play-services:7.0.0' 
    } 

添加權限內的艙單!

<!-- Include required permissions for Google Mobile Ads to run--> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

將其添加到Manifest中。

<!--This meta-data tag is required to use Google Play Services.--> 
    <meta-data android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 

    <!--Include the AdActivity configChanges and theme. --> 
<activity android:name="com.google.android.gms.ads.AdActivity"    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
       android:theme="@android:style/Theme.Translucent" /> 

文件string.xml

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string> 
+0

謝謝,但我有一個測試插頁式廣告,儘管如此,我設置了AdRequest adRequest = new AdRequest.Builder()。build();並設置我的真實單位ID。我可以上傳到商店嗎? – user3264924

3

除了什麼josedlujan告訴你這裏有一些事情要考慮。

displayInterstitial(); 

應該在應用中的一個點時,它做一些有趣的事情或者結束一個重大行動被調用。一個例子是當用戶輸入大量文本並按下完成時。

done.setonClickListener(new View.OnClickListener(){ 
public void onClick(View v) { 
displayinterstitial(); 
}}); 

你應該處理當用戶移動快,或試圖通過按backpress避免你的廣告或有緩慢的互聯網連接的情況。

public void displayInterstitial() { 
    if (interstitial.isLoaded()) { 
     interstitial.show(); 
    }else{ 
//Do something here that will loadad and show a video, an image or a toast while you wait for your ad to load to then try to show interstitial again. 
}}