简体   繁体   中英

Correct way to develope a free and paid version of an app

I have an application that has free features and paid features.

Let's suppose that an activity, in free version can perform operation A, operation B, and has a disclaimer that in order to unlock operation C, user must purchase the full version. This activit has also ads.

The same activity, in paid version, has the same operation A, same operation B and of course the operation C unlocked. This activity has no ads.

Now, I've read that the correct way to manage a free and a paid version of an app is to create 2 flavors, in order to have a structure similar to this one: 风味结构

where in main I put the "shared" parts of my app, and then I put the only-free parts in the "free" flavor, and the only-paid parts in "paid" flavor. But what about the activity described before? How can I share this activity (and it's functionality) between the two flavors, and showing or not the operation C and ads, depending on which version of my app is installed? I don't think (and don't see the point) that I need to put this activity in both free and paid version, since I don't want to write 2 times my code when I will add code of that activity, but, instead, share code that is present in both 2 versions.

While of course I will put the only-paid features in the paid version.

You could do like this:

if(BuildConfig.Flavor.equals("free")) {
    //do something
}
else if(BuildConfig.Flavor.equals("paid")) {
   //do other thing
}

and press ctrl + shift + f to search the BuildConfig.java file, you will see this file structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM