2012-03-20 46 views
5

我也跟着在下面偉大的教程:http://blog.blundell-apps.com/simple-inapp-billing-payment/BillingService有Android - 沒有簽名

我已經盡了一切的教程說,看了所有的3倍一遍又一遍,但我仍不能onReceive() : BillingReceiver.javaintent.getStringExtra(INAPP_SIGNATURE)接收簽字

這使我的應用程序崩潰,因爲應用程序無法比較簽名以驗證購買是否正確完成。

這是我BillingReceiver看起來像:

public class BillingReceiver extends BroadcastReceiver { 

    private static final String TAG = "BillingService"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      String action = intent.getAction(); 
      Log.i(TAG, "Received action: " + action); 
    if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) { 
     String signedData = intent.getStringExtra(INAPP_SIGNED_DATA); 
     String signature = intent.getStringExtra(INAPP_SIGNATURE); 
     Log.e(TAG, "<!-- SIGNATURE : "+ intent.getExtras().getString("inapp_signature")); 


     Log.i(TAG, "<!-- SIGNATURE : "+intent.getStringExtra(INAPP_SIGNATURE)); 

     purchaseStateChanged(context, signedData, signature); 
    } else if (ACTION_NOTIFY.equals(action)) { 
     String notifyId = intent.getStringExtra(NOTIFICATION_ID); 
     notify(context, notifyId); 
    } else if (ACTION_RESPONSE_CODE.equals(action)) { 
     long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1); 
     int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE, C.ResponseCode.RESULT_ERROR.ordinal()); 
     checkResponseCode(context, requestId, responseCodeIndex); 
    } else { 
     Log.e(TAG, "unexpected action: " + action); 
    } 
    } 

    private void purchaseStateChanged(Context context, String signedData, String signature) { 
      Log.i(TAG, "purchaseStateChanged got signedData: " + signedData); 
      Log.i(TAG, "purchaseStateChanged got signature: " + signature); 
      BillingHelper.verifyPurchase(signedData, signature); 
    } 

    private void notify(Context context, String notifyId) { 
      Log.i(TAG, "notify got id: " + notifyId); 
      String[] notifyIds = {notifyId}; 
      BillingHelper.getPurchaseInformation(notifyIds); 
    } 

    private void checkResponseCode(Context context, long requestId, int responseCodeIndex) { 
      Log.i(TAG, "checkResponseCode got requestId: " + requestId); 
      Log.i(TAG, "checkResponseCode got responseCode: " + C.ResponseCode.valueOf(responseCodeIndex)); 
    } 
} 
+0

我面臨同樣的問題。任何幫助讚賞。 – 2012-04-17 10:47:28

回答

5

是主帳戶在測試設備上爲您的谷歌Play開發者帳戶一樣嗎?

如果沒有,您將不會在android.test。*靜態響應中獲得簽名,除非該應用已在Play上發佈。

請參閱http://developer.android.com/guide/market/billing/billing_testing.html#static-responses-table表的全部條件。

+0

我不認爲這張桌子很有效。我應該已經在該表的第6行(已發佈的應用程序(儘管未與付費一起發佈),apk上的付費已上傳,設備上的非開發賬戶),但我得到了一個空符號。更改爲開發設備,它都可以工作。也許第一列是指已經包含計費的已發佈版本的應用程序。 – William 2012-10-01 07:39:03

+0

@William我嘗試在應用程序結算版本3 api中使用。嘗試與開發人員的手機購買保留的產品ID(靜態)。購買成功,但簽名是空的。有任何想法嗎? – Krishnabhadra 2013-01-25 09:39:48

+2

@Krishnabhadra我不認爲靜態ID會返回簽名。看到https://groups.google.com/d/topic/android-developers/PCbCJdOl480/discussion – TalkLittle 2013-02-09 05:43:27

相關問題