使用相同代码库的Android多个APK会给用户带来不便

时间:2012-04-27 16:01:46

标签: android apk

我有一个包含应用程序代码库的库项目。我有一个演示版和一个完整的版本,其中包括包含所有活动的库。大多数玩家都是从演示开始的,如果他们喜欢它,他们就会获得完整版。但是,他们通常不会立即卸载演示,并继续在他们的设备上同时使用它们。这似乎导致一个弹出窗口,询问哪个应用程序(演示或完整)打开每个活动与播放器通过活动电影。

有没有办法防止这种情况发生,或者同时在设备上安装两个APK是不可避免的副作用?

2 个答案:

答案 0 :(得分:0)

您需要在演示版和完整版之间定义不同的包。即使您的清单定义了不同的软件包(因为您在Google Play上没有两个应用程序使用相同的软件包),所以您正在调用的活动我假设存在于您的库项目中,这将使用两个版本的应用程序的库包。

要解决此问题,您应该在子项目中声明库中的清单中的每个活动。

答案 1 :(得分:0)

以下是我如何通过检测两个游戏的存在来解决问题,然后提示卸载演示版本,如果有人对未来感兴趣:

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();
        }       
    }   
}

我只是从demo和完整应用程序的onResume方法中调用此方法。