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.
Related
The app is running on Android 6 or below. But when running on Android 7 (Nougat) it throws runtime exception.
System.InvalidCastException: Unable to convert instance of type 'Android.Widget.LinearLayout' to type 'Android.Support.V7.Widget.Toolbar'.
The error is thrown in Xamarin (Visual studio 2017) at below code:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle); //Runtime error here
.... Other code ...
}
}
I've taken latest updates for All Nuget packages but not able to identify the issue. For testing I'm using Moto G4+ (Android 7.0).
Can anybody help please?
Edit 1:
Layout of toolbar is as : (Under resources > layout > toolbar.axml). This was already there when App version with Android 6 released. But Now visited app back for Android 7 issues.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
I solved this by just cleaning the entire solution and closing the emulator. Then deploy again and it should work.
I tried SeƱor Hernandez's answer without much success, then realized I had accidentally deleted Resources/Resource.designer.cs from my Android project. I had meant to delete it from disk only, expecting it to get regenerated on rebuild. It did get regenerated, but that did not add it back to the project. Doing so (right-click, include in project) solved the issue on my part.
It got solved by downloading android_m2repository_r29.zip repository from https://developer.xamarin.com/guides/android/troubleshooting/resolving-library-installation-errors/ with instruction given in same.
I also tested the issue by creating a new fresh solution and got some style "Resource not found error". That was also fixed and then the original problem also got fixed.
You get this kind of error when trying to assign a control (a UI element in your xml) on a variable that is not of the same type. I get this error frequently when I make a mess and try to assign an EditText to a TextView variable or vice versa, i. e
EditText myText = FindViewById<TextView>(Resource.Id.myText);
or
TextView myText = FindViewById<EditText>(Resource.Id.myText);
I'm pretty sure that in your case you are trying to assign an Android.Widget.LinearLayout to a variable of type Android.Support.V7.Widget.Toolbar.
I think in your case one of this variables have been defined as LinearLayout in your xml:
Resource.Layout.toolbar
Resource.Layout.tabs
Meanwhile, one of this variables have beeen defined as Toolbar in your C# code, so te cast is not possible:
ToolbarResource
TabLayoutResource
If the problem persist, you can also try to check the type Android.Support.V7.Widget.Toolbar, instead it could be Android.Widget.Toolbar in your xml or code.
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"
I have an existing Android Cordova project which uses an embedded WebView. What this means is that the Activity does not extend CordovaActivity, but instead embeds the SystemWebView and initializes within the onCreate.
The following is currently how this is being done:
Within the layout XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
.... other layout elements not related to Cordova....
<org.apache.cordova.engine.SystemWebView
android:id="#+id/cdvWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Within the Activity's onCreate:
SystemWebView systemWebView = (SystemWebView) findViewById(R.id.cdvWebView);
CordovaWebView cdvWebView = new CordovaWebViewImpl(new SystemWebViewEngine(systemWebView));
ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(this);
cdvWebView.init(this, parser.getPluginEntries(), parser.getPreferences());
Due to the bug in Lollipop versions 5.0.+ missing the "set" button, I want to implement the Crosswalk plugin into the project.
Unfortunately, all the documentation I'm finding assumes that a typical Cordova install is being used. I haven't been able to get the embedding and initialization of the XWalkWebView working correctly and keep getting a blank white screen.
Has anybody has success with a similar scenario?
I'm not sure, but this might answer your question. It seems to show implementing an XWalkWebView outside of a typical cordova project:
https://github.com/kurli/crosswalk-website/wiki/How-to-use-Crosswalk-Embedded-API-on-Android
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.
I am having an issue with using TabHost in a new Intent of type TabActivity which I hope you can point me in the right direction. Funnily it works fine when I try to view it in the original Intent : setContentView(R.layout.main)
I get a "forced closed" and within logcat, I get the following error even though my Tabhost id = "#android:id/tabhost":
02-18 22:23:11.937:
ERROR/AndroidRuntime(5944): Caused by:
java.lang.RuntimeException: Your
content must have a TabHost whose id
attribute is 'android.R.id.tabhost'
I have declared the second intent in the Manifest.xml file:
XML:
<activity android:name=".NextActivity" android:label="#string/app_name" >
Within the first activity (MainActivity), I start the second intent (NextActivity), with extras, as follows:
Intent nextActivity = new Intent(MainActivity.this,NextActivity.class);
Bundle b_next=new Bundle();
b_next.putString("s_string", myString);
nextActivity.putExtras(b_next);
In my NextActivity.java file, I get the extras and try to display the TabHost View:
public class NextActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myString;
Bundle b_initial;
b_initial = getIntent().getExtras();
myString = b_initial.getString("s_string");
setContentView(R.layout.main);
}
}
I get the same error with using the TabHost example on the Android Developer site (Hellow View):
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
Thanks in advance folks...
CLARIFICATION:
This is what I really get from LogCat:
java.lang.NullPointerException
at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java 285)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)
at android.view.ViewRoot.handleMessage(ViewRoot.java 1645)
at android.os.Handler.dispatchMessage(Handler.java 99)
at android.os.Looper.loop(Looper.java 123)
at android.app.ActivityThread.main(ActivityThread.java 3948)
at java.lang.reflect.Method.invokeNative(Native
Method)
at java.lang.reflect.Method.invoke(Method.java 521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java 782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java 540)
at dalvik.system.NativeStart.main(Native
Method)
I had the same problem. Luckily there was a quick fix:
Delete the R file.
Wait for your IDE to generate the file.
Profit!
I had copied and pasted code and noticed that in the id attribute I had:
android:id="#+id/tabs"
when what I really wanted was:
android:id="#android:id/tabs"
I have previously constructed tabhosts with an id of android:id="#+id/tabhost". Does this work for you?
You could also consider constructing your tab view programmatically:
TabHost t = getTabHost();
TabSpec tab = t.newTabSpec(label)
.setIndicator(label, icon)
.setContent(intent);
t.addTab(tab);
I also encountered this problem. I had an XML file that wasn't linked against my code properly in my res/layout. When I fixed the naming, the problem went away.
even though i had changed my main.xml to use android:id="#android:id/tabhost" like the error stated, it kept trying to use the old name. finally i found the file res/layout-port/main.xml that was identical to main.xml except used the wrong android:id. i must have added a portrait view accidentally and it was holding on to the old value. either fixing the portrait file or removing it fixes my problem.
I also had this error. For me it would appear after obfuscation(via ProGuard), pre obfuscation it was fine.
In the end I renamed my layout file to something more complex and unique, and ProGuard didn't mess up the linking. Bit easer than going down the ProGuard configeration path.
So my issue was similar to SapphireSun, though expressed via a different process(and post eclipse, just to make things that bit more difficult).
This is perhaps one of the more obscure ways to get this error, but I thought it worth a mention.
"public class NextActivity extends TabActivity" --change TabActivity to ActivityGroup.
when problem happen when you want wo run tabhost in tabhost.it is ok.
I am experiencing the same error in a team-project, when using SVN. Sometimes, eclipse uploads classes.dex and resources.ap_ from the bin folder of the project and others get it via SVN update.
Since these binary files are generated on the individual machines with individual code, thats probably where the error comes from.
Cleaning the project files (Project -> Clean) always solved the issue for us!
I had this issue along with 'ERROR: Unknown option '--no-crunch''. If you updated ADT plug-in in Eclipse but have not updated the SDK at the same time. Updating the SDK Manager in Eclipse, fixed the issue for me.