両方のゲームの存在を検出し、デモ版をアンインストールするように求めることで問題を「解決」する方法を次に示します。
public class UpdateManager {
public static void checkForBothVersions(final Activity activity) {
PackageManager packageManager = activity.getPackageManager();
//# We want to intentionally cause an Exception. This will let us know
//# whether there is only one version installed.
try {
packageManager.getPackageInfo("package.full", 0);
packageManager.getPackageInfo("package.demo", 0);
//# If we get here, then both are installed. Let's display our warning.
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Warning!");
builder.setMessage("" +
"We've detected that you have both the FULL and DEMO versions of Application installed.\n" +
"This can cause undesired results. We suggest uninstalling the DEMO version of Application." +
"")
.setCancelable(false)
.setPositiveButton("Uninstall DEMO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Uri uri = Uri.parse("package:package.demo");
//# Start the delete intent for the demo
activity.startActivity( new Intent(Intent.ACTION_DELETE, uri) );
//# We don't wanna call finish here. We want the delete Intent to open
//# and once the user closes that Intent, it should go back to the
//# calling RB Activity and call onResume where the check cycle will
//# restart.
}
})
.setNegativeButton("Continue", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
activity.startActivity(new Intent("package.lib.SplashActivity"));
activity.finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}catch( Exception e ) {
Log.i("UpdateManager", "Only one version of Application installed.");
activity.startActivity(new Intent("package.lib.SplashActivity"));
activity.finish();
}
}
}
このメソッドは、デモ アプリケーションとフル アプリケーションの両方の onResume メソッドから呼び出すだけです。