Android 应用内计费v3工作错误

Android 应用内计费v3工作错误,android,in-app,Android,In App,我在我的应用程序中添加了应用程序内计费v3,当我尝试购买一件物品时,转账成功并从信用卡中取款,但该物品没有添加到应用程序中。有什么不对劲吗 //编辑 public class GetcoinsActivity extends MainActivity { SharedPreferences prefs_coins; static final String ITEM_SKU_1 = "coins_1"; static final int RC_REQUEST = 10001; pri

我在我的应用程序中添加了应用程序内计费v3,当我尝试购买一件物品时,转账成功并从信用卡中取款,但该物品没有添加到应用程序中。有什么不对劲吗

//编辑

public class GetcoinsActivity extends MainActivity {
SharedPreferences prefs_coins;  
static final String ITEM_SKU_1 = "coins_1"; 
static final int RC_REQUEST = 10001;
    private static final String TAG = "com.chess.black";

IabHelper mHelper;
Button btn1;

int score_get = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_getcoins);

prefs_coins = PreferenceManager.getDefaultSharedPreferences(GetcoinsActivity.this);
if (prefs_coins.contains(activity_play_normal.APP_PREFERENCES_score)) 
{
score_get = prefs_coins.getInt(activity_play_normal.APP_PREFERENCES_score, 0);      
}
btn1 = (Button) findViewById(R.id.buttonBuy30);

 String base64EncodedPublicKey = "here's my key";
                    mHelper = new IabHelper(this, base64EncodedPublicKey);

            mHelper.startSetup(new 
        IabHelper.OnIabSetupFinishedListener() {
              public void onIabSetupFinished(IabResult result) 
          {
                if (!result.isSuccess()) {
                   Log.d(TAG, "In-app Billing setup failed: " + 
                result);
              } else {             
                    Log.d(TAG, "In-app Billing is set up OK");
          }
           }
        });

    }

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
    = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, 
                    Purchase purchase) 
    {
       if (result.isFailure()) {
          // Handle error
          return;
     }      
     else if (purchase.getSku().equals(ITEM_SKU_1)) {
         consumeItem();
    }

   }
};

public void consumeItem() {
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener 
   = new IabHelper.QueryInventoryFinishedListener() {
       public void onQueryInventoryFinished(IabResult result,
          Inventory inventory) 
       {           
          if (result.isFailure()) {
          // Handle failure
          } else {
                 mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU_1), 
            mConsumeFinishedListener);
          }
    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
 public void onConsumeFinished(Purchase purchase, 
       IabResult result) {

if (result.isSuccess()) {               
     score_get = score_get + 500;
     Editor editor = prefs_coins.edit();        
     editor.putInt(activity_play_normal.APP_PREFERENCES_score, score_get);
     editor.commit();
} else {
       // handle error
}
}
};

    public void OnClickBuy30(View v)
    {
        mHelper.launchPurchaseFlow(GetcoinsActivity.this, ITEM_SKU_1, RC_REQUEST,   
               mPurchaseFinishedListener);
    }

    protected void OnDestroy()
    {
        super.onDestroy();
        if (mHelper != null) mHelper.dispose();
        mHelper = null;
    }

    protected void OnActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (!mHelper.handleActivityResult(requestCode, 
                  resultCode, data)) {     
            super.onActivityResult(requestCode, resultCode, data);
          }
    }
}

好的,首先请在代码中输入日志。。。(日志d(…)

可能您的分数不会写入首选项中,因为计费过程正在另一个过程中。。试试这个

SharedPreferences yourPrefs= ctx.getSharedPreferences(ctx.PREFS_NAME,ctx.MODE_MULTI_PROCESS);

我的应用程序没有满足我的要求。。有什么不对劲吗?请提供更多信息!!这里有一个关于应用内付费v3和购买物品的教程,我想添加代码,但我不能。我可以给你我代码的链接吗?当然可以。。发布链接Alexander Sidikov,感谢编辑。那么,我应该改变什么呢?如果我将“…editor.putin(…)…”替换为“mHelper.launchPurchaseFlow”之后的方法“OnCkickBuy30”,这里的“if(result.issucess()){score\u get=score\u get+500;}将是这样,或者它也不会工作?