Admob integration in Android application

I started programming Android apps about a year ago, but I never added an Admob ad to the app. To get started, I used the Android SDK Manager (January 2015) to update the tools, documentation, SDK platform, samples, APIs and add-ons (Android Support Library and Google Play Services) to the latest versions. It seems that the old AdMob 6.4.1 is no longer in use and is replaced by Google Play services.

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

The Java sample is filled with errors. Each line in two examples of Java classes (GoogleAdsSampleActivity.java and BannerXmlActivity.java) has an error. The import lines indicate that "import com.google.android.gms.ads cannot be allowed." None of the 7 quick fixes can solve this problem. I will completely lose what to do next. I tried google search for an answer but didn’t get anywhere. I tried Project Clean and Build All and did not help. Can someone provide me some direction. Thanks.

0
source share
3 answers

I tried to integrate ads into my Android app, and now I have achieved this. Following are the steps.

1.You must have a gmail account.

2.Open www.admob.com

3. "Sign Ino Admob" will be there.

4.Select your gmail username and password.

5. After logging in, you will be asked to fill out some forms.

6. After filling, you will be taken to a new page where the option "Monetization" will appear.

7.Under Monetize you click "Monetize a new application."

8. Select "Add application manually."

9. Enter the name of the application and select "Platform".

10. Now go to the section "Selecting the ad format and ad unit with the name".

11. Select "Banner".

12. Enter the name of the ad unit.

13. Click Save.

14. You will receive an “Ad Unit ID,” which usually starts with ca. You must write it down for future use in the application.

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

1. Eclipse of the eclipse.

2.Create a new Android application project.

3.Download GoogleAdMobAdsSdk-4.1.1.jar

4. Include this jar in the libs of your project.

5. Now right-click on the project, go to the "Properties", "Enter", "Java Build", "Go", "Libraries", "Add Banks", "Add Banks" section. Select the jar that was recently added to libs.Click ok and exit.

6. Now open the AndroidManifest.xml of your project. Include the following two file permissions above the application tag.

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

7. Inside, you should 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 the 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" /> 

Note the value for googleads: adUnitId will be the identifier you created with admob.com. I asked you to mark it before. Hope you 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 to 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 } } 

It is finished. Try the above and let me know the reviews.

thanks

Linsi

+2
source

To start AdMob ads on mobile apps. You need to have identifiers and an account: 1. Create an account in your Google AdMob account. 2. To integrate ads into the application, create the application in the admob account and get the admob module ID. 3. Create the application in the Android application. 4. ad xml-code for banner advertising in the 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. Put your unitid in the layout.

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

    mAdView.loadAd (AdRequest);

  3. Remember to add permissions and ad activity to your Android.Manifest file.

If you have problems integrating adMob integration, click the 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

0
source

You can upload admob ads using AdRequest Builder as

  AdView adView; AdRequest request = new AdRequest.Builder() .addTestDevice("your id here") .build(); adView.loadAd(request); 

for more information http://www.androidcoding.in/2017/12/26/android-admob-ads-app-integrate-google-ads-android-device/

0
source

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


All Articles