Android application with billing how to handle restalls applications

I am very confused about how billing works in the application. I read the documentation, and I must have missed something because I don’t understand the last step that I need to implement in my application in order to complete this work. However, billing in the application works fine, if the user uninstalls my application and installs it again in the future, my application does not know how to determine whether a purchase was made in the application earlier. Here is a snippet of my main class where I am trying to deal with all of this:

@Override
public void onCreate(Bundle savedInstanceState)
{
    mContext = this;
    startService(new Intent(mContext, BillingService.class));
    BillingHelper.setCompletedHandler(mTransactionHandler);
}

I use class classes from the dungeon example project. I don’t understand how the code below works at the time of purchase, but repeated execution does not work to verify that something has already been purchased. I was stuck in this part for about a month, and I was very upset.

public Handler mTransactionHandler = new Handler()
{
    public void handleMessage(android.os.Message msg)
    {
        Log.i(TAG, "Transaction complete");
        Log.i(TAG, "Transaction status: "
            + BillingHelper.latestPurchase.purchaseState);
        Log.i(TAG, "Item purchased is: "
            + BillingHelper.latestPurchase.productId);

        if (BillingHelper.latestPurchase.isPurchased())
        {
            new Message("Thank you!", getApplicationContext());
            PAY_VERSION = true;
            SharedPreferences purchasePreferences = getSharedPreferences(PURCHASE_PREFERENCES, Activity.MODE_PRIVATE);
            Editor purchaseEditor = purchasePreferences.edit();
            purchaseEditor.putBoolean("purchased", PAY_VERSION);
            purchaseEditor.commit();
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }
    };

I need some way to request a server to find out if this product was purchased or not. I understand that there is a PURCHASE_STATE_CHANGEDthing, but I have no idea how to do something when it determines that the state has changed or how to initiate it for verification. I’m lost, and all I need is a good push in the right direction, because so far I’m just completely lost.

EDIT:

I also heard that you need to parse JSON, but I have no idea how to start doing this.

EDIT 2:

Should I have called this stuff to check?

BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());
BillingHelper.getPurchaseInformation(new String[] {"myItem"});

(SGS3, ICS), (GN, ICS JB ). onCreate() . , getPurchaseInformation(...) . , , JSON , ...

, :

08-27 11:54:04.271: E/BillingService(17702): BillingHelper not fully instantiated
08-27 11:54:04.271: E/BillingService(17702): BillingHelper not fully instantiated
+5
2

JSON

JSON, .

{ "nonce" : 1836535032137741465,

  "orders" :
    [{ "notificationId" : "android.test.purchased",
       "orderId" : "transactionId.android.test.purchased",
       "packageName" : "com.example.dungeons",
       "productId" : "android.test.purchased",
       "developerPayload" : "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
       "purchaseTime" : 1290114783411,
       "purchaseState" : 0,
       "purchaseToken" : "rojeslcdyyiapnqcynkjyyjh" }]
}

JSON Java.

Android JSON library

Android Billing

, , . .

,

:

  • onCreate

    BillingHelper.setCompletedHandler(handlerTransaction);
    

    .

  • onClick -

    BillingHelper.requestPurchase(this, currentMarketProduct.getMarketId());
    
0

. , , async.

:

  • .

  • , .

  • , RESTORE_TRANSACTION Google.

  • Google RESTORE_TRANSACTION. ( ,    .)

  • , Google, .

  • Google "PURCHASE_STATE_CHANGED" , . , Google, .

  • , , ( "" ).

2 5, , , , SharedPreference "APP_INITIALISED", false. , , "APP_INITIALISED" , Google RESTORE_TRANSACTION ( 2), APP_INITIALISED true ( 5).

0

All Articles