0

I am trying to have ads banner in settings page of live wallpaper , but despite my numerous attempts cant add the ads. I followed many tutorials but neither works. Please suggest me what i am doing wrong.

I followed this tutorial

http://irinaramazova.blogspot.in/2011/09/add-admob-adview-to-preferenceactivity.html

and I also saw this usefull

How do I put an admob adview in the settings screen for a live wallpaper?

neither works. My code is as follows

My Admobpreference class

public class AdmobPreference extends Preference
{

public AdmobPreference(Context context) {
    super(context, null);
}

public AdmobPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected View onCreateView(ViewGroup parent) {
        //override here to return the admob ad instead of a regular preference display
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    return inflater.inflate(R.layout.admob_preference, null);
}

}

admobpreference.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.djcharon.valentinesday"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>

<com.google.ads.adview android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adunitid="myid" ads:adsize="BANNER"  >      
</com.google.ads.adview>
</LinearLayout>

my activity_preference.xml file

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

  <com.djcharon.valentinesday.AdmobPreference android:key="adView" />
<CheckBoxPreference android:key="touch" android:title="Enable Touch" android:defaultValue="true"></CheckBoxPreference>


<ListPreference  android:key="kiss" android:title="Wallpaper" android:summary="Select the Wallpaper" android:defaultValue="Background 1" android:entries="@array/listKissSound" android:entryValues="@array/listKissSound" ></ListPreference>
<ListPreference  android:key="heartLife" android:title="Particle life" android:summary="The Particle lifecicle." android:defaultValue="20" android:entries="@array/listLifeCicle" android:entryValues="@array/listLifeCicle" ></ListPreference>

</PreferenceScreen>

I added activity in my manifest

 <activity android:name="com.google.ads.AdActivity"

          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
     </activity>

I get an error

error inflating com.google.ads.adView

Community
  • 1
  • 1
Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • Have you added the jar file of the google ads ? – GrIsHu Nov 16 '13 at 07:19
  • Possible duplicate of http://stackoverflow.com/questions/5819369/error-no-resource-identifier-found-for-attribute-adsize-in-package-com-googl and http://stackoverflow.com/questions/5613398/admob-missing-required-xml-attribute-adunitid – Stephan Branczyk Nov 16 '13 at 07:23
  • i added the jar and I also looked into the two links given above, saying mine is the duplicate. When i used the suggestion in the above links, the errors dissapear but then my app crashes when settings button is pressed. – Sandeep R Nov 16 '13 at 07:27
  • please change your xml and preferences activity as per my example. – Harshid Nov 16 '13 at 13:24

1 Answers1

0

Now Admob used google-playstore service library.

Please refer below link.

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals

Intrications
  • 16,782
  • 9
  • 50
  • 50
Harshid
  • 5,701
  • 4
  • 37
  • 50
  • That link is useless given the fact that it does not specify how to add an adview strictly through xml without the use of an activity. – Steve C. May 30 '14 at 22:28
  • @Steve check https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play-xml with subsection Create your banner in XML – Harshid Jun 02 '14 at 04:47
  • Thank you but I've tried that already. That specifies that an activity needs to be present for the xml banner to work. Where as the previous method did not. For someone like me though, having google play services utilized in your app makes it impossible to use the previous google ads lib for the previous method. Conflicts with the new lib. – Steve C. Jun 02 '14 at 12:42