How to share in-app-purchases between two Android apps

房东的猫 提交于 2019-12-01 06:56:17

问题


I have two android apps (app1 and app2), both of them are free but app2 contains an in-app-purchase upgrade.

Now I'm going to merge those two apps into the app1 (the one without the in-app-purchase).

My questions are:

  • How can I preserve the purchase that was already consumed in app2 so everyone who bought it will enjoy the upgrade on the combined app? I known I can share preferences, but I don't want to user to keep having both apps.

  • Let's say a user that purchased the in-app-purchase upgrade on app2 tries to install the new combined app1 into another device - how can I restore his purchase from app2 when it is not even installed on the other device (and probably won't be available on Google Play too)?

Thanks


回答1:


Unfortunately, this is not possible. The in-app purchases are directly tied to the unique package-id used when the applications were first created.

The only way you could preserve app2's in-app purchase would be to merge app1 into app2, thus preserving the app's purchases. Finally, if that won't work, you'd have to hand roll a solution using a service other than Google Play Services.




回答2:


It is not possible via In-App purchases API, but there are a couple of ways to work around this:

  1. Build your own backend for both apps and synchronize purchases. If you don't want to build entire backend yourself, you can use firebase authentication + firebase database. The obvious drawback, of course, is having to build and maintain backend, make users create an account, which will increase friction.
  2. If your users use will have both apps installed on your device, you could always expose a ContentProvider that shares the purchase information with another app. You can make it secure by checking the signature of a caller package and verifying it's the officially downloaded app. Alternatively to ContentProvider you could expose a service in one of the app and connect to it via AIDL from another app or you could have both apps share the user id and communicate directly. Drawback is having to ask your users to have both apps installed.


来源:https://stackoverflow.com/questions/22839133/how-to-share-in-app-purchases-between-two-android-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!