2011-12-26 9 views
11

मैं अपने कोडिंग में एक अनुप्रयोग में खरीद द्वारा जोड़ा जा रहा समझ नहीं पा रहा हूँ, यह है, जबकि अच्छी तरह से काम कर खरीद लेकिन त्रुटि देता है और आवेदन बंद कर देता है जब मैं Restore_Transaction कोड जोड़ने के लिए जब आवेदन निकाल दिया जाता है कोशिश करते हैं और है फिर से स्थापित है, मैंInApp खरीद RESTORE_TRANSACTIONS, मैं कोड बाहर

onCreate में कोडिंग नीचे जोड़ लिया है मैं

startService(new Intent(mContext, BillingService.class)); 
     BillingHelper.setCompletedHandler(mTransactionHandler); 

     if (BillingHelper.isBillingSupported()) { 
      BillingHelper.restoreTransactionInformation(BillingSecurity 
        .generateNonce()); 
     } 

लिखा था और उसके बाद मैं

का उपयोग कर हैंडलर कहा जाता है

उत्तर

5

मैं, thanx anddev को

आप खरीद के लिए जाँच करने के लिए रिक्त नहीं हो करने के लिए है अपने प्रश्न का उत्तर मिल गया

public static void verifyPurchase(String signedData, String signature) { 
    ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(
      signedData, signature); 
    if (purchases != null && !purchases.isEmpty()) { 
     latestPurchase = purchases.get(0); 
     confirmTransaction(new String[] { latestPurchase.notificationId }); 
     if (mCompletedHandler != null) { 
      mCompletedHandler.sendEmptyMessage(0); 
     } else { 
      Log 
        .e(
          TAG, 
          "verifyPurchase error. Handler not instantiated. Have you called setCompletedHandler()?"); 
     } 
    } 
} 

और Confirm_Notification में यू

if (notifyIds[0] != null) 
+0

तब समाधान क्या है? – Pabluez

+0

क्या आपको यह काम करने के लिए मिला? मुझे त्रुटियों और बल को बंद करने के अलावा कुछ भी नहीं मिलता है, इसलिए, मैं वास्तव में यह नहीं कर सकता कि आपने इस उत्तर से क्या किया है। "खरीदी गई" कक्षा के लिए कोड क्या है? – Hippyjim

+0

हस्ताक्षर डेटा और हस्ताक्षर के रूप में मुझे क्या मूल्य पारित करना चाहिए? –

1
के लिए जाँच करने के लिए हवलदार

इसका पालन करें:

confirmTransaction(new String[] { latestPurchase.notificationId }); 
यहाँ

और ऐसा करते हैं:

protected static void confirmTransaction(String[] notifyIds) { 
     if (amIDead()) { 
      return; 
     } 
     // there isn't a notifyid then this was the restore transaction call and this should be skipped 
     if (notifyIds[0] != null){ 
     Log.i(TAG, "confirmTransaction()"); 
     Bundle request = makeRequestBundle("CONFIRM_NOTIFICATIONS"); 
      ...... 
      ...... 
} 

वर्क्स एक आकर्षण की तरह मुझे फार्म .. धन्यवाद दोस्तों ...

1

आप नीचे दिए गए कोड खरीद इतिहास पाने के लिए उपयोग कर सकते हैं:

public static ArrayList<VerifiedPurchase> verifyPurchase(String signedData, 
      String signature) { 
     if (signedData == null) { 
      //Log.e(TAG, "data is null"); 
      return null; 
     } 
     if (Constans.DEBUG) { 
      //Log.i(TAG, "signedData: " + signedData); 
     } 
     boolean verified = false; 
     if (!TextUtils.isEmpty(signature)) { 
      /** 
      * Compute your public key (that you got from the Android Market 
      * publisher site). 
      * 
      * Instead of just storing the entire literal string here embedded 
      * in the program, construct the key at runtime from pieces or use 
      * bit manipulation (for example, XOR with some other string) to 
      * hide the actual key. The key itself is not secret information, 
      * but we don't want to make it easy for an adversary to replace the 
      * public key with one of their own and then fake messages from the 
      * server. 
      * 
      * Generally, encryption keys/passwords should only be kept in 
      * memory long enough to perform the operation they need to perform. 
      */ 
      String base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuKgldGQPL/xV9WKLmY62UVgEm7gsPI/T/nQxRKpYN17m8Sq3gO9nWD17wXew4oNaHmMAmArS7s7eFi3Z+XiyWil1iZvEOdBOdZD502BzujPoBa4Fu9eITPBO9tzBEdvNLXf8amnsRj53TA4bcxB2O6OcXrQIv3t3n5Dg5Nn+rJpoKSNUv7NEzJagG/2NhyjIysAObbvQ5SBQ5NgRtZlvhsTeQJPMLhRAoRcTK/+47VkhrxM3PppeGjoNRryn6d+RhMjs/nydvoQtP2V76UcUu4m+daDnK3PxOnwLt50hNtQhNf3VgixVrSKfHUWp240uEz9MHstjj8BWPH9BFF/TewIDAQAB"; 
      PublicKey key = Security.generatePublicKey(base64EncodedPublicKey); 
      verified = Security.verify(key, signedData, signature); 
      if (!verified) { 
       //Log.w(TAG, "signature does not match data."); 
       return null; 
      } 
     } 

     JSONObject jObject; 
     JSONArray jTransactionsArray = null; 
     int numTransactions = 0; 
     long nonce = 0L; 
     try { 
      jObject = new JSONObject(signedData); 

      // The nonce might be null if the user backed out of the buy page. 
      nonce = jObject.optLong("nonce"); 
      jTransactionsArray = jObject.optJSONArray("orders"); 
      if (jTransactionsArray != null) { 
       numTransactions = jTransactionsArray.length(); 
      } 
     } catch (JSONException e) { 
      return null; 
     } 

     if (!Security.isNonceKnown(nonce)) { 
      //Log.w(TAG, "Nonce not found: " + nonce); 
      return null; 
     } 

     ArrayList<VerifiedPurchase> purchases = new ArrayList<VerifiedPurchase>(); 
     try { 
      for (int i = 0; i < numTransactions; i++) { 
       JSONObject jElement = jTransactionsArray.getJSONObject(i); 
       int response = jElement.getInt("purchaseState"); 
       PurchaseState purchaseState = PurchaseState.valueOf(response); 
       String productId = jElement.getString("productId"); 
       String packageName = jElement.getString("packageName"); 
       long purchaseTime = jElement.getLong("purchaseTime"); 
       String orderId = jElement.optString("orderId", ""); 
       String notifyId = null; 
       if (jElement.has("notificationId")) { 
        notifyId = jElement.getString("notificationId"); 
       } 
       String developerPayload = jElement.optString(
         "developerPayload", null); 

       // If the purchase state is PURCHASED, then we require a 
       // verified nonce. 
       if (purchaseState == PurchaseState.PURCHASED && !verified) { 
        continue; 
       } 
       purchases.add(new VerifiedPurchase(purchaseState, notifyId, 
         productId, orderId, purchaseTime, developerPayload)); 
      } 
     } catch (JSONException e) { 
      //Log.e(TAG, "JSON exception: ", e); 
      return null; 
     } 
     removeNonce(nonce); 
     return purchases; 
    } 

आप बिलिंग विधि सर्विस श्रेणी में निम्न विधि से इस विधि को कॉल कर सकते हैं:

private void purchaseStateChanged(int startId, String signedData, 
      String signature) { 
     ArrayList<Security.VerifiedPurchase> purchases; 
     purchases = Security.verifyPurchase(signedData, signature); 
     if (purchases == null) { 
      return; 
     } 

     ArrayList<String> notifyList = new ArrayList<String>(); 
     for (VerifiedPurchase vp : purchases) { 
      if (vp.notificationId != null) { 
       notifyList.add(vp.notificationId); 
      } 
      ResponseHandler.purchaseResponse(this, vp.purchaseState, 
        vp.productId, vp.orderId, vp.purchaseTime, 
        vp.developerPayload); 
     } 
     if (!notifyList.isEmpty()) { 
      String[] notifyIds = notifyList.toArray(new String[notifyList 
        .size()]); 
      confirmNotifications(startId, notifyIds); 
     } 
    } 
+0

लेकिन हम सीधे BilllingService.purchaseStateChanged (ARG1, ARG2) की तरह इस विधि कॉल नहीं कर सकते, असल में मैं आईडी dertermine के पहले से ही जब भी एप्लिकेशन शुरू आइटम खरीदने चाहते हैं। तो मैं यह कैसे कर सकता हूँ। – AndroidDev

+0

आप कॉल करने के लिए that.There की तरह इस विधि में एप्लिकेशन बिलिंग sdk.This विधि का एक परिभाषित प्रवाह handleCommand से कहा जाता हो जाएगा की जरूरत नहीं है (आशय आशय इंट startId) विधि है जो जब BillingService onCreate में बुलाया जाएगा() विधि । –

संबंधित मुद्दे