我想通过amazon在inapppurchasing的SamplepurchaseListener.java的onpurchaseresponse()中使用共享首选项

时间:2015-03-17 12:32:08

标签: java android in-app-purchase sharedpreferences amazon

当案例成功时,我想编辑变量值,然后我想在我的项目的其他类中使用此值。 我该怎么做? 请建议我?

    switch (status) {
    case SUCCESSFUL:


        SamplePurchasingListener.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
                SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE).edit();
                editor.putBoolean("PREMIUM", true); // Storing boolean - true/false
                editor.commit();
            }
        });

        final Receipt receipt = response.getReceipt();
        iapManager.setAmazonUserId(response.getUserData().getUserId(), response.getUserData().getMarketplace());
        Log.d(TAG, "onPurchaseResponse: receipt json:" + receipt.toJSON());
        iapManager.handleReceipt(response.getRequestId().toString(), receipt, response.getUserData());
        iapManager.refreshLevel2Availability();

     break;
    case ALREADY_PURCHASED:


        Log.i(TAG,
              "onPurchaseResponse: already purchased, you should verify the entitlement purchase on your side and make sure the purchase was granted to customer");

        break;

1 个答案:

答案 0 :(得分:0)

如果您只想从其他课程中检索价值,为什么不从偏好中获取价值?像这样:

SharedPreferences sp = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE);
boolean premium = sp.getBoolean("PREMIUM", false);
if(premium) { ...

如果之前没有存储过值,则方法将返回" false"。 也许我还没有理解你的问题。