Saturday, July 2, 2011

Poor man's in app-billing for android - a good old link.

Ok, here's what I've decided to do about in-app-billing for Android. Due to the fact that you need to have a site already published before doing in-app-billing, which I don't, then I'm going with the next best thing. I'm going just publish two versions of my app. The first will be the version with 100 questions. The second will be the version with all the questions. The first will have a link to the url to the second. That's it. Of course, that means that there will be multiple versions - one "trial" and one "pro" - but that's the best I can do for now. Perhaps that may even be the case when I implement in-app billing.

It could get complicated. For example, since the Japanese Language Proficiency test (JLPT) has 5 levels, that makes 10 apps. And if I add an all-levels version, that could makes 12. Add the IOS version, and that makes 24. Owch. Of course, I'll have the same code base for each version, and vary the code only with configuration information. Otherwise, it will become unmanageable.

There's sooo much to getting this app out. There's debugging. There's adding the link to the pay version. There's adding the credits. There's testing. There's fixing the known errors in the data files. There's adding a feedback link. There are all the other changes I'll need to make to manage separate apps for the 5 levels.

I wonder if I can avoid that by just selling one app?

I don't think so. For JLPT, if I'm taking the test, I want the materials for my level. I don't want to really see the other levels - for the most part.

Ok. As the first foray into managing separate free/pay version, we'll add a link to the pay version on the first page which only displays if it's the free version. We'll first add an entry in strings.xml which says True. Then, read it in the initial display, and if the it's true, set the field displaying the link as visible, otherwise invisible. This will be pretty simple. First, add the link.

android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|center" android:paddingTop="0dp"
android:textSize="16dp" />


Ok. We already have code for this, so it's just a question of modifying it. Actually, I should add the pro/full version first. This is so that when I upload the free version, it will have a url to reference. Hmmmm...what if I make a verson for other markets?

One thing at a time. First, add the code. How about something like this:


String fullLink = "Get full version at www.temp.com" + "/" + "jlpt" + "/";

TextView textViewFullLink = (TextView) findViewById(R.id.full_link);
// String text = "Data courtesy of www.mxpkl.com";

textViewFullLink.setText(fullLink);

// pattern we want to match and turn into a clickable link
Pattern fullPattern = Pattern.compile(fullLink);

// prefix our pattern with http://
Linkify.addLinks(textViewFullLink, fullPattern, "http://");


Add the flag to strings.xml:

true


Now, add the code to check the string...

String str = getResources().getString(R.string.free);

boolean isFree = Boolean.getBoolean(str);

// add reference to full link
if (isFree) {
// and fill in the code above.


Ok, let's see if this works.

Hmmm. No. Why? Let's debug to just after it reads the boolean, to make sure that's executing ok.

Hmm, it's just stalling waiting for the debugger port. I'll be lazy in throw in a couple of toasts:


Toast.makeText(this, str, Toast.LENGTH_LONG);

// add reference to full link
if (isFree) {

Toast.makeText(this, "isFree is true", Toast.LENGTH_LONG);

Now I get the message as if the debugger was running already, asking to terminate the current session or not. Terminate.

Arggh. I can't get it to re-install. I think I need to change some code. Throw in a log statement.

I don't get why the toast isn't working. Ok, let's just use log.

Still nothing. Shall I use the infamous clean, with its incessant risk of drawing me into a R not fund annoyance? Ok, let's try.

Ok, the clean and compile worked - let's run it.

Still nothing. Ok. let's put a debug statement in the first line of code.

Yup, there it is. Dash it all, I should have checked right away that I was using the Boolean.getBoolean properly. I thought of it, but got waylayed by the slow-to-startup up debugger. Sometimes, picking through adb output, you miss things. Maybe I should try back in Eclipse instead of command line.

Anyway, here's what getBoolean does:

"Returns true if and only if the system property named by the argument exists and is equal to the string "true"."

I'm not using a system property, just a string. Boolean.parseBoolean is what I should've used, which oddly looks to be an Android, not Java method. Anyway:


Boolean isFree = Boolean.parseBoolean(str);


Ok, it's working. That's a wrap.

No comments:

Post a Comment