InMobi SDK in Android Studio shows error for IMBanner - android

I am integrating Inmobi SDK for ads in my android application. I have setup my inmobi account and have the application id from there. Below is the XML is use to setup the ad
<com.inmobi.monetization.IMBanner
android:layout_width="320dp"
android:layout_height="50dp"
android:id="#+id/banner"
adSize="15"
appId="xxxxxxxxxx"
/>
And of course i have replaced the XXXXX with my application id from the property in my Inmobi account. The first problem i observed was that appId is not being identified as a valid attribute.
Secondly if i try and do a findViewById in my activity I always get a null reference back.
What am i missing in the implementation here?

This was a very silly mistake. In Android Studio there were multiple layout files for the same activity and I was adding the AdView only to one of them.

Related

Error Integrating Inmobi in Android App

I am integrating inmobi in my android app. I have placed following code in my xml file :-
<com.inmobi.ads.InMobiBanner
android:layout_width="320dp"
android:layout_height="50dp"
android:id="#+id/banner"
ads:placementId="1474202520715"
ads:refreshInterval="60"
/>
I have initialized by main activity as :-
InMobiSdk.init(MainActivity.this, "df19afdaf27f4fb4a2c2b85e2c10bc6a");
InMobiBanner bannerAd =(InMobiBanner) findViewById(R.id.banner);
It is giving me error in placementID and refreshInterval as "No resource identifier found for attribute 'placementId'".
Can any one help me where I am going wrong.
change
xmlns:app="http://schemas.android.com/apk/res-auto"
to
xmlns:app="http://schemas.android.com/apk/lib/com.inmobi.ads.InMobiBanner"

adView.loadAd() is crashing my entire program

Im trying to integrate admob ads into my app and I've been trying to follow the tutorials on Google's APIs and their code is causing my entire app to crash.
I want to think it's because I'm testing on my phone and I havent included adRequest.addTestDevice("TEST_DEVICE_ID"); because to obtain your device id you first need to request an ad, and I am failing exactly where I am requesting an ad.
This is what I have in my main.java taken line for line from androids api tutorials. Log cat says it's crashing at adView.loadAd(adRequest);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Here's the XML
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="adUnitId"
/>
and finally here is what log cat has to say: http://imgur.com/UfB45YF
referenced api: https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play
Do you think it's crashing because I don't have my test device ID included? Or is there something else happening?
If it crashing on adView.loadAd with a NullPointerException then you have no View called R.id.adView in that Activity's layout.
Look at your Activity's onCreate and what layout you have specified in setContentView. and make sure that you aren't also using something like libGDX AndroidApplication which sets it own ContentView.
Finally do a clean build.
If you are putting the code in MainActivity.java and you have multiple layouts associated ie:
activity_main.xml
sw600dp\activity_main.xml
sw720dp\activity_main.xml
then you need to put the com.google.android.gms.ads.AdView xml code in each layout regardless of what device you are testing for.
That was my problem. Hope this helps others.
Also be sure the set your dependencies and change your manifest.
I had the same problem. When I was debugging I saw an error about the google play services version number being incorrect, and it showed the real value. I added this value to the strings.xml file:
<integer name="google_play_services_version">7095000</integer>
Once it was in, everything ran fine.

AdMob 4.3.1 adds not showing up (No AdMob ID yet (just for test), can't get ViewWidth)

First of all, I know there are a lot of questions about this topic. I searched all over the internet, but most of the tutorials are about older versions of AdMob. Also, all have some kind of different solution for the problem. They all do not work for me. I am very very close to getting these test adds into my application. They just don't show up. I get the following errors:
02-21 21:05:46.457: W/webcore(14924): Can't get the viewWidth after the first layout
02-21 21:05:46.586: W/Ads(14924): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?
02-21 21:05:46.586: D/webviewglue(14924): nativeDestroy view: 0x685300
02-21 21:05:46.586: I/Ads(14924): onFailedToReceiveAd(Invalid Google Ad request.)
I do not have a AdMob publisher ID yet, since this will be my first APP for the market (and I first have to have an APP on the market before I get an ID for the APP). What ID should I use? Currently I have (testing on my Android Phone):
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("9B08CXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//adRequest.addTestDevice("037c7xxxxxxxxxxx"); (Not right, is from console)
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);
In my XML, I have (because it also warns about viewWidth?). It is packed in a bigger LinearLayout:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dip">
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/admob_pub_id"/>
</LinearLayout>
I hope the question is small enough, but still contains enough information.
Thanks in advance!
Kinds regards,
Jos.
EDIT: I do have the manifest file changed (add permissions, activity android:name=...,
android:configChanges=...). I added the jar to a lib-folder and added it to the libraries.
You don't need to have an app already on the market to get a Publisher ID for a new app. In the Android Package URL field that's on the "Add Site/App" form, just enter "market://details?id=your.package.name". You'll of course want to replace the 'your.package.name' with your app's actual package name.
The viewWidth warnings are fine and you will likely still see them after inserting your Publisher ID.
Referring to the following errors:
07-26 15:51:24.046: W/webcore(842): Can't get the viewWidth after the first layout
07-26 15:51:24.871: W/Ads(842): Invalid unknown request error: Cannot determine request type.
Is your ad unit id correct?

How to get Google's example code working for AdMob 4.1.0 using an Android device

I want to use xml to add a banner ad to my app. To understand how to do this, I read through the Google AdMob Ads Android Banner XML tutorial. There's even example code. However, the example project doesn't display ads on my device (a Motorola xt720). I get nothing relevant in LogCat.
If I go to project settings and remove the 4.0.4 jar and add the 4.1.0 jar that I downloaded with Android SDK and AVD Manager (downloaded "Google Admob Ads Sdk package, revision 2" and the file is android-sdk-linux_86/extras/google/admob_ads_sdk/GoogleAdMobAdsSdk-4.1.0.jar), then I get this in LogCat.
ERROR/Ads(4486): AdView missing
required XML attribute "adSize".
INFO/Ads(4486): To get test ads on
this device, call
adRequest.addTestDevice("00000000000000000000000000000000");
I make that change:
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("00000000000000000000000000000000");
adView.loadAd(adRequest);
And now I get this:
ERROR/Ads(5018): AdView missing required XML attribute "adSize".
WARN/Ads(5018): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?
INFO/Ads(5018): onFailedToReceiveAd(Invalid Google Ad request.)
If I edit main.xml to fix the ads:adUnitId to be the value I have in my admob account, I still get the same error. As you can see, I am setting my adSize:
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="000000000000000"
ads:adSize="BANNER" />
So in summary:
I fixed the library version
I added my test device
I set my ads:adUnitId
But I still get AdView missing required XML attribute "adSize"
What am I doing wrong?
There are some changes to the way Admob works in version 4.1.0
There's a discussion on Google Groups about this issue and how they haven't updated the documentation.
Google employee Tim posted:
1) Remove attrs.xml (or if you need it for your own custom attributes, remove the parts related to AdViews).
2) Change the namespace in your layout from xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename" to xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
Once you have made those two changes (along with the other changes you already made), you should now see an ad.

How to implement Admob AdView in Android app

I want to use Admob in my app. I've downloaded the SDK and followed the steps. Sometimes, I get an ad in return, but most of the time, I get an entry in LogCat that says "Server did not find any ads" or something to that effect. Test mode is enabled, says the Admob site. I think I might be doing something wrong. Where can I get a step-by-step guide to insert admob ads in Android apps? The Admob developer site is rather lacking.
Also, let's assume that everything's gone well and that I'd now like to deploy the app. How do I turn off test mode for Admob ads?
Thank you.
Download the AdMob jar file http://www.admob.com/my_sites/
Create a package on your project and call it "libs" and paste this file AdMob.jar there
Right click on your project a select the library, add there the path for the ADMOB.jar you just saved.
If you're creating your AdView on your XML, you can add this line.
This is an example for testing. When you get your own ID from ADMob, place it on the adUnitID and erase the test line.
com.google.ads.AdView
android:id="#+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="a14f59e5c442767"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"
</com.google.ads.AdView>
Now go to your .java that it calling this layout and create your AdView
AdView adView = (AdView)this.findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
This is how I do and its been working good so far.
Sorry about bad english, to much code and no sleep!
just follow the instructions on this site:
http://developer.admob.com/wiki/Android#AdMob_Android_SDK
I guess you did not activate the test mode for your device or the emulator?!
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
It seems as though this might have changed to
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("E83D20734F72FB3108F104ABC0FFC738"); // My T-Mobile G1 test phone
see http://code.google.com/mobile/ads/docs/android/intermediate.html
As per Tom's comment below the value to provide for addTestDevice is actually the MD5 hash of the device ID. YOu can get this from the logcat.
Just add a permission to the Android mainfest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Check it once.
Then add this code:
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
You don't need to call it programmatically.
It took me a while until I get what device is AdMob's sdk what expecting cuz' I was thinking it was something related to the real device like ( adb devices )
But here is a comment from the official documentation that cleared it up.
There will be a log message with the code needed to add the current
device to the list of test devices
You may get an message similar to it
I/Ads(26674): To get test ads on this device, call adRequest.addTestDevice("F1254CDFBA84BDC27F5C7C6E12445D06");
All you have to do after that is to place this ID into your layout xml as below
<com.google.ads.AdView
android:layout_alignParentBottom="true"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/publisherId"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, F1254CDFBA84BDC27F5C7C6E12445D06" />
Hope it helps you guys out
Paulo Miguel Almeida

Categories

Resources