Sunday, August 7, 2011

The free app and adding a "buy" button



At last the time has come to address the free version of the app. The strategy in releasing the paid version ($3.99, the cost of Caramel Latte at Panera) first is that the whole point of the free apps (aside from some possible advertising revenue) is to promote the paid apps, so there needs to be something for them to point to.

Now, the question to ask is, when to introduce the advertising into the free apps? I would really like to get them out there as early as possible, and then include the advertisements later. This will let us get the free apps up there as quickly as possible.

So, if we're not putting the ads in yet, what's holding things up? Well, I did run across something in Google's app publishing docs about including links to your apps in the marketplace. Let's see if we can track that down.

Ok, here it is, from a previous blog entry,

http://gettingintomobile.blogspot.com/2011/08/preparing-to-publish.html

which quotes from:

http://developer.android.com/guide/publishing/publishing.html

To help users discover your published applications, you can use two special Android Market URIs that direct users to your application's details page or perform a search for all of your published applications in Android Market. You can use these URIs to create a button in your application or a link on a web page that:

Opens your application's details page in the Android Market application or web site.

Searches for all your published applications in the Android Market application or web site.

You can launch the Android Market application or web site in the following ways:

Initiate an Intent from your application that launches the Android Market application on the user's device.


Provide a link on a web page that opens the Android Market web site (but will also open the Android Market application if clicked from a device).

// This is a bit confusing. I'm thinking, though, I want I nice fat button that
// says "Get the Complete Version". I'll worry about the web site later.

In both cases, whether you want to initiate the action from your application or from a web page, the URIs are quite similar. The only difference is the URI prefix.

To open the Android Market application from your application, the prefix for the intent's data URI is:

market://

To open Android Market from your web site, the prefix for the link URI is:

http://market.android.com/

The following sections describe how to create a complete URI for each action.

Note: If you create a link to open Android Market from your web site and the user selects it from an Android-powered device, the device's Market application will resolve the link so the user can use the Market application instead of opening the web site.

As such, you should always use http://market.android.com/ URIs when creating a link on a web page.

When pointing to your apps from within your Android app, use the market:// URIs in an intent, so that the Market application always opens.

// Ok, I see - if they land on a web page from the android browser,
// it will resolve to the market app.


Opening an app's details page

As described above, you can open the details page for a specific application either on the Android Market application or the Android Market web site. The details page allows the user to see the application description, screenshots, reviews and more, and choose to install it.

The format for the URI that opens the details page is:

details?id=

The is a placeholder for the target application's fully-qualified package name, as declared in the package attribute of the element.


Opening the app details page from your Android app

To open the Android Market details page from your application, create an intent with the ACTION_VIEW action and include a data URI in this format:

market://details?id=

For example, here's how you can create an intent and open an application's details page in Android Market:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);

// that looks pretty easy.

This will open the Android Market application on the device to view the com.android.example application.


Opening the app details page from a web site


To open the details page from your web site, create a link with a URI in this format:

http://market.android.com/details?id=

For example, here's a link that opens an application's details page on Android Market:

App Link


When clicked from a desktop web browser, this opens the Android Market web site to view the com.android.example application. When clicked from an Android-powered device, users are given the option to use either their web browser or the Android Market application to view the application.

// Ok, I'll wait until after the apps are published to add these.


Let's add this intent. First, change the indicator on the core project to free.

Now, make a copy of the shell app for the free package.

svn export svn export JlptQuiz5Full JlptQuiz5Free

Then import it into the Eclipse, rename the package, update the new package name in the manifest.

Errors, but none you can see. Clean...ok. That does it.

Now I'm getting app not managed from the google licensing server. But the free ones can't have licensing code in them. So, here's where my careful foresight comes in. The Licensing part is included as a separate project, off the shell project
So, now I can just remove that code and the library reference.

In properties,android properties, got rid of my licensing project and the android licensing library. Now let's run it.

Why is the system so slow? I just rebooted it. Ok, it's building the workspace, and for some reason doing it incredibly slowly. I just force quit it. Is firefox a problem? It's seems to have become slower the past few years. Chrome is so much faster.

What? Eclipse is hanging again? Why?

Ok, a bit of googling suggest the projects might be messed up. I probably deleted the dependencies in the from java build path instead of the android selection. The best thing to do is delete the project and start from scratch. Ok, let's run a build all to be sure.

Let's give it another try...

Yes, the problem I had had was, again, I didn't originally use the android project setting, I went to the java build path, then android. That probably mucked something up, without a doubt in fact.

Now let run it again...

Ok, it runs, but I have some of my own license checking code in the core project. I don't really need this - I'm going to delete it...

Uh-oh. The core project is giving me the dreaded R error. Clean? Nope. Any r imports? Nope.

Oh, I had turned off the build automatically switch. Ok, still erroring out, but try clean again now the build is turned out. Ok, that did it.

Rerun the free project.

Ok, there it is. Well, a lot of the links are missing from the start page. Ah, I see, it's the splash screen. The problem is, it's my licensing activity that launches the real display. Since I don't really need that anymore, I can just change the manifest to launch the real starting activity. That's probably the simplest. Yeah, that's good. I'll get rid of the licensing activity and boostrap activity, and change the title and app label to something with "free" in it.

And the package name, of course.

<resources>
<string name="app_label">JLPT 5 Free Test</string>
<string name="app_title">JLPT 5 Free Japanese Vocabulary Quiz Test</string>
<string name="level">5</string>
</resources>

Ok, let's try that one.

Crash on StartActivity not found - because it needs the name qualified in the manifest:
com.jlptquiz.app.StartActivity.

Ok - but it's missing the link to the full version...

Iit turns out I was checking for < when it should have been <=

Ok, and there's the link. Hmmm...it will be faster to just use the link then set up a button.

Let's try that for now.

Well, there's a problem. Well, no, I can get the level from the application context/shared preferences.

Let's try this for a link:

int level = SharedPreferencesUtil.getJlptLevel(appState);

String packageName = "com.kanjisoft.jlpt" + level + ".full";

String paidLink = "http://market.android.com/details?id=" + packageName;


And here's the strangeness about the link where the only way to get it to highlight the way I wanted it to was to compile the pattern as a blank, and have the whole url inside paid link.

String paidLink = "http://market.android.com/details?id=" + packageName;


// get the link field for setting up link
TextView textViewFullLink = (TextView) findViewById(R.id.full_link);

textViewFullLink.setText("Get Complete version");

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

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


Sugar. I forget that I'm using the shell activity to set the level in the application state. That's ok, I'll just pull back the old manifest.

Hmmm, somehow, it's not finding my location on the market with the link. I can get it to work if I put in a normal link. But even if I hardcode the recommended url, substituting my package name, it still is not found. It may have something to do with calling from an app as opposed to a web page. Anyway, I think we're going to have to put a button.

I'll test to see if the link works from a web page...yes, that works beautifully.

All right, I give up - it's going to have to be a button. I'm going to try to fit it in with the first two - so there will be three across. No, then the paid version will show it two - unless I use two separate layouts. No chance of that. How do other apps do this? Well, for now, I'll put it there, and just set it invisible if it's free.

Ok, to the layout. No, no way it's on the same line. It's got to be below the other two. It takes up too much space otherwise, and of course the setVisible off doesn't re-align it.

It's starting to look do-able. It'll be underneath the other two, and wider and thinner. But it's getting stuck on the left. It needs this:

android:layout_gravity="center_vertical|center_horizontal"

Excellent. A bit more formatting and it's looking good. Now the easy part - the code. GUI stuff can be such time-sink. This one worked out ok, though.

And here's the code:

/**
* @param appState
* @param payButton
*/
private void handlePayButton(Button payButton) {

payButton.setVisibility(View.VISIBLE);


payButton.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

// Log.d(TAG, "settings onClickListener");

AppState appState = (AppState) StartActivity.this.getApplication();

int level = SharedPreferencesUtil.getJlptLevel(appState);

String packageName = "com.kanjisoft.jlpt" + level + ".full";

String link = "market://details?id=" + packageName;

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri
.parse(link));
startActivity(intent);

}

});

}


Ok, let's try this.

Ouch - it's still not finding it. And the button is slightly out of alignment.

Ok, fixed the alignment - but why isn't it finding the page?

Copy the details straight of the web lookup.

market.android.com/details?id=com.kanjisoft.jlpt5.full

Got it! Phew. Must have been typo somewhere in the package name.

Here's what the "free" page looks like (larger image than the one shown at the top:

2 comments:

  1. Thank you for this valuable information, I would like to suggest best magazine publishing software. magplus providing best services are you still unsure of whether to go digital or not? Don’t you already have enough reasons to be convinced? Like it or not, the world is going digital.

    ReplyDelete
  2. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. monitor gps

    ReplyDelete