HelloWorld HelloWorld - 22 days ago 7
Android Question

Codename One wasPurchased() method : Is it supported on Android devices?

For my Codename One app, I am trying to figure out whether I can tell if an in-app-purchase (non consumable) has already been bought on Android (code shown in my other SO question).

According to this 2014 question it seems that managed purchases are not supported on Android. However when I test

isManagedPaymentSupported()
on Android it returns true, and I can buy an In-App-Purchase.

So managed purchases seem to be supported on Android. However
wasPurchased()
remains false even after successful purchase although this Google Group discussion seems to say that
ẁasPurchased()
does work indeed.

I tried to reach the source code for that
wasPurchased()
method
but could not find anything usefull (maybe I did not find the right code pieces).

So I am completely at lost, since my code works on the simulator as expected but not on a real Android device (which could also be faulty). Consequently could someone tell me if
wasPurchased()
is working on Android (in that case my Android device is faulty) or if I have to implement some native Android code to do what
wasPurchassed()
is expected to do ?

EDIT November 10th 2016 : Solved with suffix "_nonconsume

As written in the blog post @Shai showed in his answer by default Google play considers the product as consumable. That's why in case of non consumable product
wasPurchased()
returned false. To make Google Play treat the In-App-Product as non-consumable, you have to use the suffix "_nonconsume" in the SKU name in the developper console (eg : "myappfull_nonconsume"). Then wait a few hours after submitting your app to the alpha testing channel and when the app is available, Google play will remember the purchase and
wasPurchased()
will work as expected.

Any help appreciated,

Answer

This might be more useful: https://github.com/codenameone/CodenameOne/blob/master/Ports/Android/src/com/codename1/impl/android/CodenameOneActivity.java#L191-L209

That's the piece that actually gets called. Support for managed purchases was added a few years ago when we migrated to the new Android in-app-purchase 3 API: https://www.codenameone.com/blog/migrating-to-androids-in-app-purchase-30.html

Comments