Java / Android Developer, Trainer, Writer, Speaker

Monday, November 10, 2014

Like the article?

Well! Hello Android Developers! It’s been amazing what Google doing since its birth! But, it’s also some kind of pain to cope up with its updates and newer things. It’s been painful for some people to set up new Admob for PhoneGap in new updated system. Previously we used to use an Admob jar file, but now system has been changed.  We’ll see this today. The developers who are from web developing background loves to code work with PhoneGap for Android Application development.



For the post, the first recommendation is reading this post: Google Play New Android SDK Setup for AdMob ( AdSense )


In this post I’ll just show the code placement along with file placement. PhoneGap files placement steps:

Step 1: Place cordova.js file in your project folder > assets > www > from workspace.

Step 2: Place XML folder to your project folder > res from workspace.



If you don’t know what I’m talking about, or what is cordova.js file / xml folder, please follow this: http://phonegap.com/install/


Read More: 9 Ideas for Career ( Online Money Making ) based on your Love



Now, The code placement steps:


Step 1: First of all, place the below code in import section, for PhoneGap cordova:

import org.apache.cordova.DroidGap;



Step 2: We need more importing for AdMob Advertisement. Place the below codes in import section too:

import com.google.android.gms.ads.*;



Step 3: Now rename this line ‘public class Second extends Activity ‘ to ‘public class MainActivity extends DroidGap ‘ for using Phonegap



Step 4: Now declare a private variable ‘private AdView adView;’ just before onCreate method.

Step 5: Into onCreate method place this line   super.loadUrl("file:///android_asset/www/index.html"); right after super.onCreate(savedInstanceState);

Step 6: Make the onCreate Method public from protected.



Step 7: Now, place the below codes into onCreate method.

            // Create the adView. [ www.imrubel.blogspot.com ]

            adView = new AdView(this);

            adView.setAdSize(AdSize.BANNER);

            adView.setAdUnitId("ca-app-pub-bbbbb5816378148090/6054xxxxxxxxx");

            LinearLayout layout = super.root;

            layout.addView(adView);

            //  [ www.imrubel.blogspot.com ]

            AdRequest request = new AdRequest.Builder()

          .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)

          .build();         

            //  [ www.imrubel.blogspot.com ]

            // Start loading the ad in the background.

            adView.loadAd(request);


Replace setAdUnitID with your Ad Code.

We are done! Now you can compile and see output. If you are not clear yet, you can follow the below image.



admob ad placement in phonegap for android



After successful placement, Admob add will appear like below image. I took a screenshot for you guys.

PhoneGap Admob add



Read More: R cannot be resolved to a variable error in Android Development and Solution

I hope you did it successfully, leave a comment if you face any problem. Share this post for others then others will share something good for you too. Subscribe for more.

Read More: Career in Mobile Application Development for You : My Experience

1 comment:

  1. You can make $20 for each 20 minute survey!

    Guess what? This is exactly what large companies are paying for. They need to know what their customer needs and wants. So large companies pay $1,000,000's of dollars per month to the average person. In return, the average person, like me, participates in surveys and gives them their opinion.

    ReplyDelete