Ok, we're making progress. We've just set up the licensing validation to be called from "bootstrap" activity, and come up with a nice, clean solution to handling licensing validation in only the paid program. But, there's still plenty of work to do. Since google doesn't allow upload of free apps to the marketplace if they have the validation library, we need to separate the licensing validation code into a separate library, which will be only included int the paid versions.
Let's create that project now, create the class and copy in the ValidateLicense class code. Ok, we need to add the licensing library to the project for these classes:
import com.android.vending.licensing.AESObfuscator;
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;
Here's how it's done, from somewhere on google:
To download the LVL component into your development environment, use the Android SDK and AVD Manager. Launch the Android SDK and AVD Manager and then select the "Market Licensing" component, as shown in the figure below. Accept the terms and click Install Selected to begin the download.
It's already installed - ah, here we go:
After downloading the LVL to your computer, you need to set it up in your development environment, either as an Android library project or by copying (or importing) the library sources directly into your existing application package.
In general, using the LVL as a library project is recommended, since it lets you reuse your licensing code across multiple applications and maintain it more easily over time. Note that the LVL is not designed to be compiled separately and added to an application as a static .jar file.
Ok, but, how to import it as a library again? Let's see project settings on the old project...
Ok, it look like you add it as a source library. In my case, it's under workplace/marketlicensing/library/src
Ah, there's the project, oddly name com_android_vending_licensing. So, now I just add it as a library project, but how? Ah, there it is, the add project. There we go.
And go to project, properties, android and check off that it's a library.
Ah, there's a problem. In order to kill the called app, it needs a backwards reference to the activity that called it, which is different. Why does it need that? I just thought it was a generic activity. Ah good, I just needed to delete the import.
Ok, great! Now I'm going to delete the reference code for that call from the common source...
And also add the common code as a another shared project, just like the downloaded licensing library...
ctrl-shift-o (for mac) to add back in all the required imports...
Now, add my new project library to the "shell" app as a project. Hmm, why isn't the regular library showing up on the shared projects list? How did I add it, again?
Ah, here it is:
In the Package Explorer, right-click the dependent project and select Properties.
In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
Click Add to open the Project Selection dialog.
From the list of available library projects, select a project and click OK.
When the dialog closes, click Apply in the Properties window.
Click OK to close the Properties window.
That's what I was missing. I'll go back and fix it on my licensing project. The trick is to remember "Android". I just posted that!
Ah, perfect. Now let's go ahead and add the new licensing project to the "shell" project.
And, finally remove the android licensing library it from the "core" project...
And delete the ValidationLicense.java class.
Whew!
Ah, and change the import statement on the shell bootstrap activity to point at the new library project.
Man. That was intense. I just got hung up on how to include the hew library project. I should read my own blog postings!
Ok, how about a test?
Perfect! I got my error message. NOW we can look ut uploading the new app. I'll tackle that in my next blog.
No comments:
Post a Comment