I trying to implement the AdMob banner in my app but it not showing. I already used the banners and i use always same way.. I have a FrameLayout
with the view. This FrameLayout is inside a LinearLayout
;
<FrameLayout
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MyId"
ads:adSize="BANNER"
ads:loadAdsOnCreate="true"/>
</FrameLayout>
this is the java part:
adview = (AdView) findViewById(R.id.adView);
adview.loadAd(new AdRequest());
and in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
with all meta-data:
<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:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
You are mixing things up. You are using both old and new api with GoogleAdMobAdsSdk-6.4.1.jar. You should stick to the new api (admob via google play services). Make sure you don't have the GoogleAdMobAdsSdk-6.4.1.jar in your project's /libs/
folder. Then, reference the google play services library within your project and make the following changes:
In your layout file, change:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MyId"
ads:adSize="BANNER"
ads:loadAdsOnCreate="true"/>
to:
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
In your java code, change:
import com.google.ads.AdRequest;
import com.google.ads.AdView;
adView.loadAd(new AdRequest());
to:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
adView.loadAd(new AdRequest.Builder()
.build());
Just hit Ctrl + Shift + O
to import to the right packages
You can also follow the official guide on migrating to the new admob here.
Make sure you use the google play services version 4 or later. You can check its manifest xml file for the versionCode. Thanks
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다