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

前端 未结 2 415
死守一世寂寞
死守一世寂寞 2021-01-21 14:12

Just started playing with Android and I\'m trying to create an app that has free and paid version. I\'m new to Java as well but I\'ve managed to create a simple working applicat

相关标签:
2条回答
  • 2021-01-21 15:01

    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);
    
    0 讨论(0)
  • 2021-01-21 15:10

    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;
    }
    
    0 讨论(0)
提交回复
热议问题