Francis Markle
Francis Markle

Reputation: 1

Admob Integration into Android Application

I started programming Android apps about a year ago but have never integrated the Admob ad into an app. To get started, I used the Android SDK Manager (Jan, 2015) to update the Tools, Documentation, SDK platform, samples, APIs, and Extras (Android Support Library and Google Play Services) to the latest revisions. It looks like the old AdMob 6.4.1 is no longer used and has been replaced with the Google Play Services.

Based on the Google Mobile Ads documentation [ htpps://developer.android.com/google/play-services/ads.html ], I downloaded and imported into Eclipse the sample located at "/extras/google/google-play-services/samples/admob/".

The Java sample is full of errors. Every line in the two sample Java classes (GoogleAdsSampleActivity.java and BannerXmlActivity.java) has an error. The import lines state that "The import com.google.android.gms.ads cannot be resolved". None of the 7 quick fixes available solves the problem. I'm at a complete loss as to what to do next. I've tried Google search for an answer but got nowhere. I tried Project Clean and Build All and no help. Can anyone provide me with some direction. Thanks.

Upvotes: 0

Views: 4992

Answers (2)

Donix Technologies
Donix Technologies

Reputation: 1

To start with AdMob ads in your mobile applications. You need have some ids and account: 1. Create account in Google AdMob Account. 2. To integrate ads in your application, create application in admob account and get admob unit id. 3. create application in android application. 4. ad xml code for banner ad in layout file.

 <com.google.ads.AdView
    xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    googleads:adSize="BANNER"
    googleads:adUnitId="Your Ad Unit Id" />
  1. Place your unitid here in layout.

  2. in Java file, add code as shown below:
    AdRequest adRequest = new AdRequest.Builder().build();

    mAdView.loadAd(adRequest);

  3. do not forget to add permissions and ad activity in Android.Manifest file.

If you find any problems regarding integrating adMob integration then please click on link: https://donixtech.blogspot.in/2017/03/howto-fix-google-admob-ad-error-failed.html

https://donixtech.blogspot.in/2017/04/google-admob-integration.html

Upvotes: 0

Lincy David
Lincy David

Reputation: 195

I was trying to integrate ads into my android app and now I have achieved it. Below are the steps.

1.You need to have a gmail account.

2.Open www.admob.com

3."Sign Into Admob" link will be there.

4.Sign In using your gmail username and password.

5.After login you will be asked to fill some forms.

6.After filling you will be taken to a new page where there will be a option called "Monetize".

7.Under Monetize you have click "Monetize a new app".

8.There select "Add App Manually".

9.Type App Name and select Platform.

10.Now go to "Select ad format and name ad unit".

11.Select "Banner".

12.Type an Ad Unit name.

13.Click Save.

14.You will get "Ad Unit Id" which usually starts with ca-You have to note down it for future use in app.

These are the steps you have follow as a first step. Now the next steps,you have to perform it in android code.I am using eclipse.

1.Open eclipse.

2.Create new Android Application Project.

3.Download GoogleAdMobAdsSdk-4.1.1.jar

4.Include that jar in libs of your project.

5.Now right click project,go to,Properties,got to,Java Build,go to,Libraries,go to,Add jars,Select the jar that you recently added to the libs.Click ok and exit.

6.Now open AndroidManifest.xml of you project.Include the below two permission to the file above application tag.

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

7.Inside you have to declare AdActivity as follows

<application>
.
.
.
 <activity
 android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
 android:theme="@android:style/Theme.Translucent" />
.
.
.
</application>

8.Open xml layout activity_main and paste the following code.

 <com.google.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        googleads:adSize="BANNER"
        googleads:adUnitId="Your Add unit id" />

Please note the value for googleads:adUnitId will be the id which you have generated using admob.com.I have asked you to note it down before.Hope u remember.

9.Open MainActivity ,paste the following code in oncreate

AdView mAdView;

oncreate()
{
        mAdView = (AdView) findViewById(R.id.ad);
        mAdView.setAdListener(new MyAdListener());

        AdRequest adRequest = new AdRequest();
        adRequest.addKeyword("sporting goods");
        mAdView.loadAd(adRequest);
}

10.Add the following code in the MainActivity as an inner class

private class MyAdListener implements AdListener {

        @Override
        public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {

        }

        @Override
        public void onReceiveAd(Ad ad) {

        }

        @Override
        public void onDismissScreen(Ad arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLeaveApplication(Ad arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPresentScreen(Ad arg0) {
            // TODO Auto-generated method stub

        }
    }

Finished.Try the above and let me know the feedback.

Thanks

Lincy

Upvotes: 3

Related Questions