Admob Integration into Android Problem

I am trying to integrate admob into android, I ended up not succeeding. The document says that you must provide a device identifier to receive ads for real devices. Could you help me with this. But I get ads in the emulator by installing AdManager.TestEmulator.

+1
source share
3 answers

Just configure AdMob, I use it in several applications. After you define your application on the AdMob website / control panel, you will see your unique identifier for your application.

Then you just need to add the AdMob banner to your project, if you use simple eclipse, create a libs folder in the project folder, copy the admob jar and eclipse there, right-click and go to "Build path / Add to build path".

Then open the manifest file and add the following to the tag

<meta-data android:value="<YOUR APPLICATION ID FROM ADMOB CONTROL PANEL>" android:name="ADMOB_PUBLISHER_ID" /> 

Then decide what activity you want to show, I usually place an ad right at the bottom of LinearLayout, so add the following.

 <com.admob.android.ads.AdView android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" myapp:secondaryTextColor="#CCCCCC" /> 

At the top of the layout definition, in which you define the xml namespace, you will see

 xmlns:android="http://schemas.android.com/apk/res/android" 

also add a link to the admob namespace so you have:

 xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/net.dbws.fv" **<-- change package (net.dbws.fv) to your package** 

Finally, create a file called attrs.xml in the values ​​folder and paste the following:

 <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="com.admob.android.ads.AdView"> <attr name="backgroundColor" format="color" /> <attr name="primaryTextColor" format="color" /> <attr name="secondaryTextColor" format="color" /> <attr name="keywords" format="string" /> <attr name="refreshInterval" format="integer" /> </declare-styleable> </resources> 

Then you should be good to go, of course, I did not need to do something else for real devices, unlike the emulator, the above should work for you. You do not always see the announcement, especially the first few times when you start the application, but if you see ADMOB entries on your logcat output when you start the application, you can be sure that it works.

Hi

+6
source

In the Sites and Applications section, when you’re signed in to AdMob, hover over the name of your application. You should see two buttons: Reporting and Settings Management. Click Manage Settings. I think this is what they mean by “control panel”.

You will see the "Publisher ID" at the top of the page. This is what you need for your AndroidManifest.xml file to replace "YOUR_ID_HERE".

The string "ADMOB_PUBLISHER_ID" remains the same as it is.

+2
source

Hello dear, find the simple steps to add admob to your application ...

1- Download GoogleAdMobAdsAdk-6.4.1.

2- Paste it into the lib folder.

3- go to https://apps.admob.com/?pli=1#monetize/adunit:create

4- get your identifier from here by selecting "Monetize new app".

5- change the layout file -

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <com.google.ads.AdView xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adSize="BANNER" ads:loadAdOnCreate="true" ads:adUnitId="Your Unit Id you generated" /> </RelativeLayout> 

6- put this permission in android manifest file

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

enjoy

0
source

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


All Articles