我想检测如果任何应用程序内购买的是由用户,当应用程序被启动的第一次尝试更新使用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));
我不知道什么是错的这个代码。 预先感谢您的帮助和新年快乐! :)