Saturday, August 13, 2011

MobFox - Implementing ads in Android, II




Yesterday, we decided to implement ads in our Android app, because we found a nice little guide which walks us through the steps, in "Advertising on Android implementation - Part 1 http://gettingintomobile.blogspot.com/2011/08/advertising-on-android-implementation.html".

We had gotten to the point of downloading the MobFox sdk. So, I guess that means, now comes the hard part - putting the ads into the program.

So, let's open the SDK and see what's in there. Ok, theres a pdf - let's read it.

It says: "Quick Integration"

1) Start eclipse. // check
2) Create a new android project // We've already got an app.

The instructions are really about adding to an existing app, although they start out with creating a new app, probably for the sake of simplicity in the code display.

So, let's just jump down to the first relevant step, which is to add a new "lib" *source* folder to the project.

Then, copy the mobfox sdk to it.

Now, add a couple of permissions to the manifest.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>


And add an activity declaration:

<activity android:name="com.mobfox.sdk.InAppWebView"/>

And include this somewhere in one of the views:

<com.mobfox.sdk.MobFoxView
android:id="@+id/mobFoxView"
android:layout_width="fill_parent"
android:layout_height="50dp"
publisherId="<enter your publisher id here>"
/>


Let's run it - ok, it crashed, because why?

E/AndroidRuntime( 821): Caused by: java.lang.ClassNotFoundException: com.mobfox.sdk.MobFoxView in loader dalvik.system.PathClassLoader[/mnt/asec/com.kanjisoft.jlpt5.full-2/pkg.apk]
E/AndroidRuntime( 821): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
E/AndroidRuntime( 821): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 821): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 821): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
E/AndroidRuntime( 821): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
E/AndroidRuntime( 821): ... 20 more
W/ActivityManager( 101): Force finishing activity com.kanjisoft.jlpt5.full/.BootStrapActivity
W/ActivityManager( 101): Activity pause timeout for HistoryRecord{40780ca8 com.kanjisoft.jlpt5.full/.BootStrapActivi

Somehow, the fact that it's a separate source library is making it unavailable to the "shell" project. Humm.

Maybe I should create it as a separate project after all, as a library project.

This is confusing. Should it be a library shared to the shell project? Let's try that.

Hmm. What should the package name be? I don't know if it will make any difference from including it as a lib from the original project.

I think adding it as a library on the shell projects may solve the problem. Let's give it a whirl, shall we?

No. As it turns out, the first thing that actually makes it find the class is adding it as an external jar to the shell project.

And the add appears. Very nice:




But, when I click on it:

E/AndroidRuntime( 1545): FATAL EXCEPTION: main
E/AndroidRuntime( 1545): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kanjisoft.jlpt5.free/com.mobfox.sdk.InAppWebView}; have you declared this activity in your AndroidManifest.xml?

So, let's change the add as external jar to the core lib.

That doesn't work - class not found. We'll have to add it to each project specifically. Actually, only the free projects, since I'm not putting adds in the paid ones.

Just added the jar and activity to the 4 free project. And now, the click reveals this modfox test image:













1 comment:

  1. wish ur article had more info on implementing the sdk than what they already told us and the error you got cause you didn't know to implement an external jar.. glad to hear that you got the basics of eclipse down, but, if you know something about implementing in app ads it would be great if you wrote it here. thanks bye

    ReplyDelete