2015-05-13 55 views
0

朋友你好我wnat加時賽的AdMob在我的應用程序集成,因此我設置以下爲AdMob相關棒棒糖5.1設備無法顯示

Main.java

public class Main extends Activity{ 

AdView adView; 
RelativeLayout mRelativeLayoutRoot; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.advs); 
    mRelativeLayoutRoot=(RelativeLayout)findViewById(R.id.root); 


    adView = new AdView(this); 
    adView.setAdSize(AdSize.BANNER); 
    adView.setAdUnitId(getResources().getString(R.string.admob_unit_id)); 
    adView.setId(11); 
    LayoutParams lp; 
    lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); // You might want to tweak these to WRAP_CONTENT 
    lp.addRule(mRelativeLayoutRoot.ALIGN_PARENT_BOTTOM); 
    mRelativeLayoutRoot.addView(adView, lp); 
    AdRequest adRequest = new AdRequest.Builder() 
    .build(); 

    adView.loadAd(adRequest); 

} 

代碼}

清單.xml

<?xml version="1.0" encoding="utf-8"?> 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="21" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

<application 
    android:allowBackup="true" 
    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=".Main" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.google.android.gms.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

</application> 

</manifest> 

在i上述代碼廣告顯示僅運行傑利貝恩奇巧Lolliop設備移動設備5.1它沒有顯示任何想法如何我可以解決這個問題?

編輯

當我運行這個鱈魚EIN Micomax的Android One手機(棒棒堂5.1)它不顯示廣告上

+0

你有在設備或模擬器上測試嗎? –

+0

Haresh Chhelana是的,我測試了三星Galaxy Grand Qutroo(Jelly Bean),sumsang galaxy core 2 SM-G355H(Kitkat) –

+0

Haresh Chhelana:看到我的編輯部分即時通訊設備 –

回答

4
**integration of AdMob:-** 

**in your main Class:-** 

    **Public Variables:-** 

    AdView mAdView; 
    boolean firstAdReceived = true; 
    ImageView imageView; 

    **Oncreate() :-** 

    mAdView = new AdView(DashBoardActivity.this); 
     mAdView.setAdSize(AdSize.SMART_BANNER); 
     mAdView.setAdUnitId(getResources().getString(R.string.banner_ad_unit_id));  //its a your admob key declare in String File. 

     mAdView.setAdListener(new AdListener() { 

     @Override 
     public void onAdLoaded() { 
     firstAdReceived = true; 
     // Hide the custom image and show the AdView. 
     imageView.setVisibility(View.GONE); 
     mAdView.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onAdFailedToLoad(int error) { 
     if (!firstAdReceived) { 
     // Hide the AdView and show the custom image. 
     mAdView.setVisibility(View.GONE); 
     imageView.setVisibility(View.VISIBLE); 
     } 
     } 

     }); 
     LinearLayout layout = (LinearLayout) findViewById(R.id.adLayout); 
     layout.addView(mAdView); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     mAdView.loadAd(adRequest); 
     imageView = (ImageView) findViewById(R.id.image); 
     imageView.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
     Intent intent = new Intent(Intent.ACTION_VIEW, 
     Uri.parse(Const.INNOVIFY_WEB_URL)); // its your admob url 
     startActivity(intent); 
     } 
     }); 



**Create XML file for admob:-** row_adview.xml 

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

    <LinearLayout 
     android:id="@+id/adLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="fitCenter" 
      android:src="@drawable/default_ad_image" 
      android:visibility="visible" /> 
    </LinearLayout> 

</LinearLayout> 

Hope it will helps you...!!! 
0

建議你在創建AdView的開始您的活動而不是代碼中的XML佈局。這將有助於消除一些潛在的錯誤。

接下來,請確保您已將2個設備的設備ID添加爲測試設備ID。

最後,查看您的2個設備的logcat,並查看Admob日誌在未加載廣告時的說明。

相關問題