Android main project with library project - how to pass setting between projects

喜夏-厌秋 提交于 2019-12-02 01:10:38

Your code works, but I'm not sure storing your paid/free flag in your manifest is the best solution if you are using the same apk to have both free and paid (unlock) functionality. Instead I would do this by adding a method in the library project which allows any project to set a flag on whether the app is free or paid.

ex in library project:

    void setAppPurchasedMode(boolean purchased)
    {
        appPurchased = mode;
    }

and in your library, you can check vs this flag:

    if (appPurchased)
        // show unlocked content

So in your main project, if the app has been paid for:

    Library.setAppPurchasedMode(true);

OK I managed to solve this. In the Application Manifest, I simply set the android:label property and referenced this using the code below.

In Manifest:

android:label="My Free App"

To reference this

//Are we using free or pro version?
if (this.getApplication().getApplicationInfo().loadLabel(this.getPackageManager()).toString().equals("My Free App")) 
{
freeVersion = true;
} else {
freeVersion = false;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!