playing with Admob java class and monkey
Monkey Targets Forums/Android/playing with Admob java class and monkey
| ||
OK.. this is where I put my hand up and admit that I'm not really sure what I am doing, but wondered if some one has some input. I've been playing with the AndroidManifest.xml file and res/main.xml file so that I can add an AdMob view and shrink the monkey view slightly. All alterations are based on http://code.google.com/mobile/ads/docs/android/fundamentals.html AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.monkey" android:versionCode="1" android:versionName="1.0"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="MonkeyGame" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation"/> </application> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> </manifest> main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <view class="${APP_PACKAGE}.MonkeyGame$MonkeyView" android:id="@+id/monkeyview" android:keepScreenOn="true" android:layout_width="240px" android:layout_height="320px" /> <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="MY_AD_UNIT_ID" ads:adSize="BANNER" ads:loadAdOnCreate="true"/> </LinearLayout> It all compiles but crashes on execution. I suspect its because the src/com/google/ads java class files don't get copied over during the compilation from my targets/android folder. Is there a way of forcing this? I am doing it the right way? Shall I stop right now and do something else instead? Has someone done this already? PS.. after using BlitzMax.. I'm loving Monkey |
| ||
looking further into this last night... I remove the .build/android folder for each build so all files should come from the targets folder. If I remove the targets/android/src folder, the monkeygame.java file still appears in the src/com/monkey folder when I compile. So I'm assuming that there's a compilation script somewhere that re-compiles monkeygame.java on the fly. I think I need to plug into the same script so that it copies over the src/com/google/ads folder at the same time. |
| ||
ive done fallowing steps and its working for me: add this AdView adView = (AdView)this.findViewById(R.id.adView); adView.loadAd( new AdRequest()); to onCreate in MonkeyGame class in MonkeyGame.Java file this is my main.xml in layouts folder <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <com.google.ads.AdView android:id="@+id/adView" ads:adUnitId="PUT YOUR ID HERE" ads:adSize="BANNER" ads:loadAdOnCreate="true" android:layout_width="match_parent" android:layout_height="wrap_content"/> <view class="com.CoDaQ.game1.MonkeyGame$MonkeyView" android:id="@+id/monkeyview" android:keepScreenOn="true" android:layout_width="fill_parent" android:layout_weight="0.0" android:layout_height="wrap_content"/> </LinearLayout> additional attributes in values folder <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="com.google.ads.AdView"> <attr name="adSize"> <enum name="BANNER" value="1"/> <enum name="IAB_MRECT" value="2"/> <enum value="3" name="IAB_BANNER"/> <enum value="4" name="IAB_LEADERBOARD"/> </attr> <attr name="adUnitId" format="string"/> <attr format="string" name="loadAdOnCreate"/> </declare-styleable> </resources> applicatin is running but MonkeyGame View is always overriding adv and they are not visible. Same code run without monkeyGameView works fine, adds are displayed properly in a baner after loading. |
| ||
nice one... many thanks for the update.. looks like i was missing the java file code. Did you also edit your android manifest file? Looks like we need to bring the ad view to the front of the views somehow. I'll have a look later |
| ||
i will go into java engine of MonkeyView it might be hardcoded somewhere what is happening now so far i was managed to run add in monkey game (counter on add server is increased) but user does not see add in application maybe this is even better..... |
| ||
For user it might be better, but as soon as someone finds out that you're cheating the system you get yourself in trouble. |
| ||
not sure people would get into trouble. but not having the ad appear defies the point of the ad as you get paid per click not view... |
| ||
why cheating ? this is how android was designed. I dont know why MonkeyView is over all other controls....LinearLayout layout = (LinearLayout)findViewById(R.id.liner); AdView adView = new AdView(this, AdSize.BANNER, "CODE HERE"); layout.addView(adView); AdRequest request = new AdRequest(); adView.loadAd(request); This is purely done in MonkeyGame OnCreate Method and it works for non created in monkey projects (just add name of main Linear Layout to linear in main.xml) <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/liner" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <view class="com.monkey.MonkeyGame$MonkeyView" android:id="@+id/monkeyview" android:keepScreenOn="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> |
| ||
replacing the main.xml with something like this... makes text appear aligned withe bottom of the screen without affecting the ratio of the monkey screen. I assume replacing the textview with the ad xml would work... <?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:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <view class="${APP_PACKAGE}.MonkeyGame$MonkeyView" android:id="@+id/monkeyview" android:keepScreenOn="true" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:layout_width="wrap_content" android:id="@+id/tvBelowScroll" android:text="AD TEST BOX" android:layout_height="50px" android:textStyle="bold" android:textSize="18dip" android:layout_alignParentBottom="true"></TextView> </RelativeLayout> new xml with ad code (non tested) <?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:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <view class="${APP_PACKAGE}.MonkeyGame$MonkeyView" android:id="@+id/monkeyview" android:keepScreenOn="true" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <com.google.ads.AdView android:id="@+id/adView" ads:adUnitId="PUT YOUR ID HERE" ads:adSize="BANNER" ads:loadAdOnCreate="true" android:layout_width="match_parent" android:layout_height="50px" android:layout_alignParentBottom="true" /> </RelativeLayout> |
| ||
for me still no effect, in eclipse it looks ok but monkeyView does not change size at all i am using one of the samples in monkey bananas |
| ||
on my machine I can see "AD TEST BOX" at the bottom of the screen. Not tested any ad code.... does the textview box work? PS I had to change LinearView to RelativeView to get it to work on mine. Did you change this too? |
| ||
yes I did, ive changed it ive checked with adView object, does not work :( when switched into normal text box its working maybe this the reason : MonkeyView extends GLSurfaceView when i use adView with normal project without MonkeyView its fine |
| ||
Thats a shame.. sooo close maybe this the reason : MonkeyView extends GLSurfaceView This is where my knowledge bottoms out Maybe rather than specifying 50px, keep to the wrap_content constants |
| ||
i still can't run any admob code.... I've put the java files into targets\android\src\com\google\ads but they dont get copied over during compilation Also.. which monkeycode.java file am i editing? (.build dir or monkey folder) many thanks for your help Rich |
| ||
oh sorry i havent mentioned ? i am just build monkey project and finish job in Eclipse. So i dont care about target or whatever just edit files in src folder and change the xml files what i actualy did is to modify existing MonkeyGame in monkey exported project instead of updating target at least app is working |
| ||
Ok not sure how I did it... But I seem to have AdMobs in Monkey.. heres a screen.. sorry for the bad quality. ![]() I will to work out what i did so that i can post up a guide.. |
| ||
ps bed time now |