This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Android Preference Admob ad integration  RSS feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello . How can i show admob ads in android preference screen .


my preference xml is



and my settings class that extends preference activity is



Thank you
 
Saloon Keeper
Posts: 5038
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't AdMob a commercial product that should come with documentation? I'm sure they have example integration code available on their site.
 
siddharth sekhar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Isn't AdMob a commercial product that should come with documentation? I'm sure they have example integration code available on their site.



Hello , Yes . But not on a preference screen . Earlier when I have to integrate admob I used to use the following in the xml layout


and in the  corresponding java file this code


But not able to use this code in a preference activity
 
Tim Moores
Saloon Keeper
Posts: 5038
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "not able" mean? What did you try, and how did or didn't that work out?
 
siddharth sekhar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What does "not able" mean? What did you try, and how did or didn't that work out?



I tried to put the admob view in the preference xml but cannot do that . it gives a warning like "element com.google.android.gms.ads.AdView is not allowed here" , so i cannot access it on my settings class
 
Tim Moores
Saloon Keeper
Posts: 5038
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am near certain that it is possible. What results did you get when you googled that error message? I'm sure people have run into that before.

Also post the layout XML where you tried that.
 
siddharth sekhar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:I am near certain that it is possible. What results did you get when you googled that error message? I'm sure people have run into that before.

Also post the layout XML where you tried that.



After some hunting , I found this solution .

1 create a xml layout that would hold the ad view (ad_layout.xml)
2 create a class file extending preference that will define the xml file (AdPreference.java)
3 place this xml file in our Preference xml (preference.xml)

xml file that will hold the adview


Class file for defining the xml file


Place it in our preference xml


It is working , But I have some confusions

a. Where should I Place MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713"); line of code

b. How the class AdPreference is associated with ad_layout.xml . How this class know which layout file to look for . since there is no mention of as_layout.xml file in this class

c. How can I place the ad on the bottom of the screen . At this time it is just below the edit text .

d. The solution only uses the unit ID of the ad . So we do not need the admob app ID here.

 
Tim Moores
Saloon Keeper
Posts: 5038
134
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

b. How the class AdPreference is associated with ad_layout.xml . How this class know which layout file to look for . since there is no mention of as_layout.xml file in this class



The association is rather obvious, isn't it:

<com.mygdx.game.AdPreference android:layout="@layout/ad_layout"/

 
siddharth sekhar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:

b. How the class AdPreference is associated with ad_layout.xml . How this class know which layout file to look for . since there is no mention of as_layout.xml file in this class



The association is rather obvious, isn't it:

<com.mygdx.game.AdPreference android:layout="@layout/ad_layout"/



Thanks for pointing out the obvious for me. I was searching for something like R.layout.ad_layout  and missed to see what you have shown to me .
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!