Error Integrating Inmobi in Android App - android

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"

Related

getting an ad response. ErrorCode: 1

I am testing my application in device it is showing the error in debug logcat what is this error and how to solve this?
The error is
There was a problem getting an ad response. ErrorCode: 1
my xml code is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/accent_material_light"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
my code to display the ads is
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
and in manifest file I am adding.the code is working fine but the ads are not displaying I am testing it on my device
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
Try to use Ad unit ID.
You may mistakenly use the APP ID or PUBLISHER ID.. (Like my mistake)
Sample Ad Unit ID (it contains xxxxx/xxxxx)
ca-app-pub-9390048287444061/3221111032 - correct one
Sample App ID (it contains xxxxx~xxxxx)
ca-app-pub-9390048287444061~1222077830 - wrong one
the issue is solved by adding the ad-Unit Id Other than publisher id and adding the test device id through AdRequest
as you say,
you have done all attempt write all code perfectly in manifest as well as build.gradle file.
this same problem was to me.
so after that i have resolved this problem by correcting my ad-mob unit id and also
it was written in uppercase.so i modify it to lowercase and works perfectly.
This works for me.Hope this help others too!!.
I had the same problem.
I believe Error Code 1 is due to many different reasons, but mine was wrong adSize. I set up for NativeAdExpress, but was giving wrong dimensions in XML, MEDIUM_RECTANGLE worked for my NativeAdExpress view.
try adding below code to you gradle file.
compile 'com.google.android.gms:play-services-ads:8.1.0'

InMobi SDK in Android Studio shows error for IMBanner

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.

Google Play Ads not working android 4.4 (required xml attribute ads:adSize was missing)

My application was working with android 4.2 and using Admob x.x.x.jar file few days back.
i just configured android sdk 4.4 and i noticed Google play ads are not longer working, also found it should be upgraded as well so what i did following:
Before My XML Was:
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
ads:adSize="BANNER"
ads:adUnitId="asdadadasddas"
/>
Today I updated it
<com.google.android.gms.ads.AdView android:id="#+id/adView"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="asdadadasddas"
ads:adSize="BANNER"
/>
My Manifest
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
values => Integer.xml
<integer name="google_play_services_version">5089034</integer>
and it give me following error
Note: I am not using any java code to display it is that necessary?
any help would be appreciated.
I appreciate answers of all developers actually i solved this problem by combining the answers of all so i would like to enter steps here that might help others.
XML Layout:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-***"
ads:adSize="BANNER"
/>
Two mistakes in my code were:
1) xmlns:ads value was wrong & this mistake pointed out by donfuxx
2) i was using old AdUnitId with following format: a15220c7a5f3775 but in latest AdMob its format is entirely different as used in above example.
Note:
If you use old "ads:adUnitId" it will show blank ad and this was the case with me.
Javacode
Java code is also required
AdRequest adRequest = new AdRequest.Builder()
.build();
AdView adView = (AdView) view.findViewById(R.id.adView);
adView.loadAd(adRequest);
Then again i found another error:
Class not found exception although i had imported the Google Play project in my application.
Then i found an article in which it was mentioned copy Google Play Jar inside your "libs" folder and it will be automatically included in your android private libraries to resolve this issue.
Final Issue
No need to put value in integer.xml inside your app because when you include Google play services project inside your app, it will automatically pick version value out of it in your manifest file.
So these were the issues i faced during migration of adMob and will help others to implement it quickly.
You can still use ads:adSize xml attribute!
However, your xml namespace setting is wrong in the adview element, because it refers to the legacy admob:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
but since you already use the google play admob, you should use:
xmlns:ads="http://schemas.android.com/apk/res-auto"
that is why the ads: attributes were not recognized.
More infos see the official admob migration guide.
You should no longer be setting your adUnitId/adSize in the layout. Instead do:
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
Layout:
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
And finally,
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("XXXXXXXXXXXXXXXXXXXX")
.build();
adView.loadAd(adRequest);

Admob 6.1.0 for monodroid

I have an app made with monodroid, it's on release stage (ready to get released) but I would like to have a free ad-supported version of my app. I've been searching the web for a tutorial of Admob 6.1.0 implementation on monodroid without any luck. I'd have to mention that I've never worked with ads before.
I was wondering if anyone has been able to use Admob 6.1.0 on monodroid and if you could share your knowledge
I've seen this source code and also this tutorial, but I just can't manage to understand correctly how to implement it. I't would be nice if someone could make an answer as a community wiki so it can help others to get introduced to Admob in monodroid
EDIT:
Tried Greg Shackles sample step by step, i'm now getting this error android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView. Any sugestion of how to make it work?
EDIT 2:
Changed the XML file and now getting 2 new errors: Java.Lang.NoClassDefFoundError and System.TypeInitializationException. XML looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/Background2"
>
<com.google.ads.AdView android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="AD_UNIT_ID_GOES_HERE"
ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
And adview is called like this:
public class MyActivity : Activity
{
private View _adView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.AboutActivityLayout);
AdMobHelper.RegisterEmulatorAsTestDevice();
_adView = FindViewById(Resource.Id.Ad);
AdMobHelper.RequestFreshAd(_adView);
loadData();
}
}
The first error you got "android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView" is related to the Jar Build Action setting.
You should check two things first:
the jar file has the Build Action property set to "AndroidJavaLibrary"
the java file called "AdMobHelper.java" should have the Build Action property set to "AndroidJavaSource"
It seems to me that the error you are getting now is related to the java file not being correctly configured as an AndroidJavaSource.

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.

Categories

Resources