简体   繁体   中英

Android Switch flavor after in-app purchase

I implemented In-App-Billing in my app with a window that opens and handles the transaction. If this was successful I would like to switch the flavor of the app from "free" to "pro".

How can I do that?

What do you mean with "switch"? Android flavors are not meant to alter runtime behaviour: they are useful when you need to produce different APKs from the same project. If you really want a different APK for purchasing users, you should find a way to download the other APK after the purchase, for example redirecting the users to a different app page on the Play Store. Downloading a new app is maybe to complex for some users, so the easiest way to do this is to have only one APK and include all the resources in it. If you really want to redirect the users to a different Play Store page, you can do something like this:

String packageName = "your.paid.app.application.id";
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}

This code handles also the case of users without the Play Store app on their device.

After the download of the second (paid) app, the users will have both apps installed on theirs phone.

You can find more details about flavors here .

If you prefer instead to manage all the logic in a single APK, you can refer to this .

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