Instead of creating a light and a full version of my app, I decided to go the freemium way and offer a button to upgrade from the light to the full version.
The application is only available on the Google Play Store. So I created an in app purchase in the Play Store as described http://mobilecodetogo.blogspot.fr/2013/03/android-does-it-better-in-app-purchase.html.
Here is the code that I implemented :
if (buyFull) {
if (ParametresGeneraux.getPurchase().isManagedPaymentSupported()) {
String[] skus = {"ParametresGeneraux.getFullVersionSKU()"};
if (ParametresGeneraux.getPurchase().isItemListingSupported()) {
Product[] products = ParametresGeneraux.getPurchase().getProducts(skus);
String items = "";
if (products != null) {
for (Product p : products) {
items += p.getDescription();
}
}
Dialog.show("Produits intégrés", "Les produits intégrés sont " + items,
"OK", "Cancel");
}
// On achète
ParametresGeneraux.getPurchase().purchase("ParametresGeneraux.getFullVersionSKU()");
} else {
Dialog.show("Évolution impossible", "Impossible d'évoluer vers la version complète. Votre compte n'a pas été débité.", "OK", "Compris");
}
Where ParametresGeneraux.getPurchase() is doing Purchase.getInAppPurchase().
When I test it on the simulator with an Android skin (Nexus 5) the listing is not shown and it always results in a null pointer exception after executing the purchase :
java.lang.NullPointerException
at com.codename1.impl.javase.JavaSEPort$82$5$1.run(JavaSEPort.java:7936)
at com.codename1.ui.Display.processSerialCalls(Display.java:1152)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1096)
at com.codename1.ui.Display.mainEDTLoop(Display.java:997)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
On the contrary on the device few hours after submitting the app, the purchase is charged (so item is found and not null). However when I restart the app it is still in light version.
Here is how I test if it is a light version (in the init method from the main class) :
ParametresGeneraux.setPurchase(Purchase.getInAppPurchase());
ParametresGeneraux.setLightVersion(true);
if (ParametresGeneraux.getPurchase().isManagedPaymentSupported()) {
if (ParametresGeneraux.getPurchase().wasPurchased(ParametresGeneraux.getFullVersionSKU())) {
ParametresGeneraux.setLightVersion(false);
}
}
According to this 2014 SO question (and the mentioned RFE that has been closed since then) I assume wasPurchased should also work on Android. So I don't know why it does not work.
Actually my questions are :
Is it possible to test in app purchase with the simulator ?
Is wasPurchased the right method to pick up to check whether the user has bought the feature ?
Thanks a lot for giving me hints!