Я пытаюсь определить, принадлежат ли какие-либо из покупок в приложении пользователю, когда приложение запускается при первой попытке обновить режим Pro приложения, используя SharedPreferences.Следующий код, к сожалению, не работает: (
if (version.equals("null")) { //checking version of the app, if it is unset equals first launch
SharedPreferences.Editor editor = appinfo.edit();
version = currentversion;
editor.putString("version", version);
editor.apply();
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (mHelper == null) return; //IabHelper mHelper;
Purchase purchase = Inventory.getPurchase("sku1");
Purchase purchase2 = Inventory.getPurchase("sku2");
Purchase purchase3 = Inventory.getPurchase("sku3");
if (purchase != null || purchase2 != null || purchase3 != null) {
final SharedPreferences ispro = getApplicationContext().getSharedPreferences("ispro", 0);
SharedPreferences.Editor editor = ispro.edit();
editor.putInt("ispro", 1);
editor.apply();
}
}
};
startActivity(new Intent(MainPage.this, Changelog.class));
EDIT1: после некоторых изменений код теперь выглядит так:
final List<String> skus = Arrays.asList("sku1", "sku2", "sku3");
if (version.equals("null")) {
SharedPreferences.Editor editor = appinfo.edit();
version = currentversion;
editor.putString("version", version);
editor.apply();
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
}
if (mHelper == null) return;
mBroadcastReceiver = new IabBroadcastReceiver(MainPage.this);
IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
registerReceiver(mBroadcastReceiver, broadcastFilter);
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (mHelper == null) return;
Purchase purchase = Inventory.getPurchase("sku1");
Purchase purchase2 = Inventory.getPurchase("sku2");
Purchase purchase3 = Inventory.getPurchase("sku3");
if (purchase != null || purchase2 != null || purchase3 != null) {
final SharedPreferences ispro = getApplicationContext().getSharedPreferences("ispro", 0);
SharedPreferences.Editor editor = ispro.edit();
editor.putInt("ispro", 1);
editor.apply();
}
}
};
try {
mHelper.queryInventoryAsync(true, skus, null, mReceivedInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
}
}
});
startActivity(new Intent(MainPage.this, Changelog.class));
Я не знаю, что не так с этим кодом.Заранее благодарю за помощь и с Новым годом! :) 1007 *