Android: how to integrate admob in the app?

I tried to integrate the admob banner in my application for several hours, but I could not do this, so I created a new application whose sole purpose is to show the admob banner, but it does not work either. here is the code

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AdView adView = new AdView(this, AdSize.BANNER, "XXX"); adView.setVisibility(View.VISIBLE); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); layout.addView(adView, adParams); setContentView(layout); AdRequest adRequest = new AdRequest(); adView.loadAd(adRequest); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } } 

and here is my manifest file

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.zzzzzz_admobtest" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.zzzzzz_admobtest.MainActivity" 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.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> </application> </manifest> 

what am I doing wrong?

Also, when I output adView.isActivated () and adView.isReady (), both of them are false.

I use "XXX" instead of ID because I don't have one. Could this be a problem?

I am using a device. Here are the errors on ligcat

08-07 22: 43: 04.248: E / ActivityThread (24181): Failed to find provider information for com.google.plus.platform 08-07 22: 43: 04.454: E / Ads (24181): JS: Uncaught ReferenceError : AFMA_getSdkConstants not defined ( http://media.admob.com/:1 ) 08-07 22: 43: 04.454: E / Web Console (24181): Uncaught ReferenceError: AFMA_getSdkConstants not defined in http: //media.admob. com /: 1

last 2 errors can be fixed with this code

  (new Thread() { public void run() { Looper.prepare(); adView.loadAd(new AdRequest()); } }).start(); 

as I understand it, the first of them is not a mistake, but just a warning. so why doesn't it work?

+4
source share
6 answers

I use "XXX" instead of ID because I don't have one. Could this be a problem?

Yes. Absolutely yes. Register for an Admob account. Get the identifier and use it.

+2
source

The metadata tag is missing in Android-manifest.look in already available resources. Example

  <meta-data android:name="ADMOB_PUBLISHER_ID" android:value="XXXX" /> 
+1
source

This question is old, but I want to answer it because a new technology has appeared that makes AdMob integration very easy. In most cases, you don’t need to encode anything additionally, just create an .apk file and Admob will be automatically added to it.

  • Enter FGL Enhance . Choose which SDK to integrate. You can select several different SDKs using this service, for this tutorial we will select only Admob from "I want to choose the SDK myself."

In fact, you can integrate more than 20 SDKs by simply selecting their check box. This list includes various ad providers, crash reports, Dolby Audio, etc.

  1. Choose which development technology was used to create your application. If you want to show / hide the banner, you will need to connect a light drag and drop library and add 1 line of code. Depending on the selected technology, you will be provided with a link to a sample code and a link to a connector library.

But if you just want the banner to be present on your screen all the time, which is the easiest solution, you do not need to change the game code! This solution is called ZeroCode, and it works for any development technology: an event for .apk and .ipa that you received from an HTML5 game or from Game Maker.

  1. On this page you can choose the types of ads that will be displayed in your application. Interstitial ads between levels Awarded video - video with a reward for viewing Flexible banner - banner that can be hidden / shown in the game code Persistent Banner - banner that will always remain on the screen (but rotation of the banner is available starting from AdMob settings) Pre- Roll - announcements shown at application launch (for example, in ketchapp games).

The last two types are marked as ZeroCode. You do not need to code anything in your game to be integrated. For our example, we will choose only a permanent banner.

  1. Download our app.

  2. On the next screen, we can choose the type of banner. We can use, for example, SMART_BANNER or any other type of banner from the AdMob Help. We will also enter the banner ID from our AdMob account. When creating a banner in the AdMob account, we can set the update interval.

  3. The final step is to choose a signature method. You can use your own developer certificate, after which you can send the game to the store immediately after entering AdMob. You can select a test certificate to test the application on your own device. Or you can download an unsigned app and sign it locally before heading to the store.

  4. Another progress bar ...

    And here we are!

Enhance is completely free for developers. You will receive the same amount from advertising, as if you integrated the ads manually. FGL earns revenue from SDK vendors because, in essence, FGL Enhance makes SDKs more attractive to new developers.

source: http://www.airapport.com/2016/09/tutorial-how-to-quickly-integrate-admob.html

+1
source

Add only two lines in your onCreate

 AdView ad = (AdView) findViewById(R.id.adView); ad.loadAd(new AdRequest()); 

And add AddView to your XML like

  <com.google.ads.AdView android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adSize="SMART_BANNER" ads:adUnitId="@string/ads_unit_id" ads:loadAdsOnCreate="true" /> 
0
source

You can download the full source code from here.

Add the following lib dependency

  compile 'com.google.android.gms:play-services-ads:7.8.0' 

For smart banner

Add the following things to the xml file

  <com.google.android.gms.ads.AdView android:id="@+id/ad_view" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adSize="SMART_BANNER" ads:adUnitId="@string/banner_ad_unit_id" /> 

Add the following things to java file

  mAdView = (AdView) findViewById(R.id.ad_view); AdRequest adRequest = new AdRequest.Builder().build(); // Start loading the ad in the background. mAdView.loadAd(adRequest); 

For interstitial advertising

  mInterstitialAd = new InterstitialAd(MainActivity.this); mInterstitialAd.setAdUnitId(getResources().getString(R.string.full_screen_ad_unit_id)); AdRequest adRequestFull = new AdRequest.Builder().build(); mInterstitialAd.loadAd(adRequestFull); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); // Full screen advertise will show only after loading complete mInterstitialAd.show(); } }); 
0
source
  adView = (AdView) findViewById(R.id.adView); AdRequest request = new AdRequest.Builder() .addTestDevice("ca-app-pub-3940256099942544/6300978111") .build(); 

Already answered here

fooobar.com/questions/1495677 / ...

0
source

Source: https://habr.com/ru/post/1495674/


All Articles