且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建一个"授权附加"我的Andr​​oid应用程序?

更新时间:2021-12-04 21:33:48

您可以使用 PackageManager getInstalledPackages() getInstalledApplications()来简单地检查是否安装许可证包。

You can use the PackageManager's getInstalledPackages() or getInstalledApplications() to simply check if the license package is installed.

或者,如果你想要一些更复杂的,你可以给主要的应用程序和许可证APK相同的在清单的用户ID。这意味着,应用程序可以访问您的数据(共享preferences时,SQLite数据库,等等)。然后许可证的应用程序只需要运行一次;它可以存储在共享数据指示所述扩展功能应启用的值。主要的应用程序只需要检查这个标志并相应地改变它的行为。

Or, if you want something a bit more sophisticated, you can give the main app and the license apk the same user id in the manifest. This means that both apps can have access to your data (Shared Preferences, SQLite DB, etc). Then the license app just needs to be run once; it can store a value in the shared data indicating that the extended functionality should be enabled. The main app just needs to check this flag and alter its behaviour accordingly.

的第二种方法的优点是,许可证的应用程序可以被运行之后被卸载,并且主应用程序将继续允许扩展功能。

The advantage of the second approach is that the license app can be uninstalled after being run, and the main app will continue to allow the extended functionality.