8

Ich bin mit aktuellen Code für den Kauf für Vorsatz Kauf AufrufIn App im statischen Codes

Bundle buyIntentBundle = mService.getBuyIntent(3, pContext.getPackageName(), "android.test.canceled", "inapp", "bGoa+V7g/yqDXv"); 
Set<String> allKeys = buyIntentBundle.keySet(); 
Object responseCode= buyIntentBundle.get("RESPONSE_CODE"); 
Object intent= buyIntentBundle.get("BUY_INTENT"); 
Log.i(TAG,"buyIntentBundle"+buyIntentBundle.keySet()+"responseCode"+responseCode+"intent"+intent); 
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); 
if (pendingIntent != null) { 
    pContext.startIntentSenderForResult(pendingIntent.getIntentSender(), 2013, new Intent(), Integer.valueOf(0), Integer.valueOf(0),Integer.valueOf(0)); 
} 

Jetzt onActivityResult ich bin Überprüfung

if (requestCode == 2013) {   
    Log.i(TAG, "onactivity result called inside request code"); 
    int responseCode = intent.getIntExtra("RESPONSE_CODE", 0); 
    String purchaseData = intent.getStringExtra("INAPP_PURCHASE_DATA"); 
    String dataSignature = intent.getStringExtra("INAPP_DATA_SIGNATURE");  
    if (responseCode == Constants.BILLING_RESPONSE_RESULT_OK) { 
    try { 
     JSONObject jo = new JSONObject(purchaseData); 
     String sku = jo.getString("productId"); 
     Toast.makeText(pContext, "You have bought the " + sku + ". Excellent choice, adventurer!", Toast.LENGTH_SHORT); 
     JSONObject o = new JSONObject(purchaseData); 
     String mOrderId = o.optString("orderId"); 
     String mPackageName = o.optString("packageName"); 
     String mSku = o.optString("productId"); 
     long mPurchaseTime = o.optLong("purchaseTime"); 
     int mPurchaseState = o.optInt("purchaseState"); 
     String mDeveloperPayload = o.optString("developerPayload"); 
     String mToken = o.optString("token", o.optString("purchaseToken")); 
     try { 
      mService.consumePurchase(3, pContext.getPackageName(), mToken); 
     } catch (RemoteException e) { 
        e.printStackTrace(); 
     }//consumePurchase 
    } 
    catch (JSONException e) { 
       Toast.makeText(pContext, "Failed to parse purchase data.", Toast.LENGTH_SHORT); 
       e.printStackTrace(); 
    } 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_USER_CANCELED) { 
     Toast.makeText(pContext, "User cancelled purchase.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) { 
     Toast.makeText(pContext, "Your Device doesn't support inapp billing.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE) { 
     Toast.makeText(pContext, "Item is not available for billing.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_DEVELOPER_ERROR) { 
     Toast.makeText(pContext, "Can't purchase item due to some developer error.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ERROR) { 
     Toast.makeText(pContext, "Can't purchase item due to some error in response.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) { 
     Toast.makeText(pContext, "You already own this item.", Toast.LENGTH_SHORT); 
    }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) { 
     Toast.makeText(pContext, "You don't own this item.", Toast.LENGTH_SHORT); 
    } 
} 

Da ich „nenne android.test.canceled "Also sollte ich BILLING_RESPONSE_RESULT_USER_CANCELED diese Antwort erhalten, aber es zeigt sich als Zahlung erfolgreich und gibt responseCode als BILLING_RESPONSE_RESULT_OK mit keinem anderen Parameter in diesem intent.getExtras zurück. Ich versuche, statische Antworten http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-static

Dank & Grüße !!

+0

Ich war durch das gleiche Verhalten verwirrt und ich denke, die tatsächlichen Android-Entwickler sollten den Code ändern. Wenn Sie (oder eine andere Person) die user_cancelled-Antwort noch testen müssen, drücken Sie einfach die Rücktaste. Der Antwortcode lautet BILLING_RESPONSE_RESULT_USED_CANCELED. – artsince

Antwort

3

Du bist gerade nicht:

if (resultCode == Activity.RESULT_OK) { 
    .... 
} 

Es ist möglich, dass der Prozess nicht erfolgreich abgeschlossen wird. Und da der Standardwert für responseCode in dem Fall, dass die Taste "RESPONSE_CODE" nicht in intent vorhanden ist "0" ....

int responseCode = intent.getIntExtra("RESPONSE_CODE", 0); 

.... responseCode wird initialisiert Constants.BILLING_RESPONSE_RESULT_OK ==>0.

Versuchen Sie sich mit:

int responseCode = intent.getIntExtra("RESPONSE_CODE", -1); 

Und einen letzten else Block hinzufügen -1 zu handhaben.

+0

Der resultCode entspricht RESULT_OK bei Verwendung von android.test.canceled – Thys

+0

@MrThys Ok. Haben Sie versucht, 'int responseCode = intent.getIntExtra (" RESPONSE_CODE ", -1);'. Wird 'responseCode' immer noch auf' 0' initialisiert? – Vikram

+0

Jep, ich habe den Standardwert auf -1 gesetzt und es gibt immer noch 0 zurück – Thys

Verwandte Themen