> trial-demo that can be unlocked by downloading a 'license key'-app. Is
> this better than having two versions of your app around?
better. Generally I've not had many problems from the customer side,
but I provide quite a bit of guidance: in various dialogs that appear,
in the Market description for the license, on my app's website, and
even in a small HTML "license help" page I bundle with the APK and
open in a WebView if the user's having trouble. For me, I think it's
still easier than trying to keep the source code of free+paid versions
synchronized, but YMMV.
In answer to some of the other questions floating around on this
thread...
My code (in the "trial") to check for the license looks like this:
final PackageManager pkgMgr = context.getPackageManager();
final int sigMatch =
pkgMgr.checkSignatures(appContext.getPackageName(),
"com.package.of.license");
if (sigMatch == PackageManager.SIGNATURE_MATCH) {
// License found
...
key for this to work. That's a pretty central part of this approach.
And in my license, rather than removing the MAIN & LAUNCHER intents
from the manifest, I have code like this in the activity's onCreate:
final PackageManager pkgMgr = getPackageManager();
final int sigMatch = pkgMgr.checkSignatures(this.getPackageName(),
MAIN_APP_PACKAGE_NAME);
if (sigMatch == PackageManager.SIGNATURE_MATCH) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(MAIN_APP_PACKAGE_NAME,
MAIN_APP_PACKAGE_NAME + ".MainActivity"));
startActivity(intent);
// Remove this app from the Launcher
pkgMgr.setComponentEnabledSetting(
new ComponentName(PACKAGE_NAME, PACKAGE_NAME + ".LicenseActivity"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.download_instr)
.setPositiveButton(R.string.download, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse("market://details?id=" +
MAIN_APP_PACKAGE_NAME));
try {
startActivity(marketLaunch);
} catch (Exception e) {
Toast.makeText(LicenseActivity.this, R.string.no_market,
Toast.LENGTH_LONG).show();
}
LicenseActivity.this.finish();
}
})
.setNegativeButton(R.string.cancel, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
LicenseActivity.this.finish();
}
})
.create().show();
involved. It covers the following eventualities:
- If the user has the main ("trial") app already installed, this
starts its MainActivity, then removes itself from the Launcher
- If they don't, it shows them a dialog with a link to a market search
for it