我正在按照此处的教程集成 google pay API 以获取我的应用程序的资金。到目前为止,我已经成功地进行了收费,但我发现在成功转账时很难获得收费金额。
我使用的谷歌钱包依赖是
implementation 'com.google.android.gms:play-services-wallet:15.0.1'
当我向另一个人提出请求时,我想在MainActivity
's中获得收费金额。但只有电子邮件地址和帐单状态。我能想到的唯一合乎逻辑的方法是以某种方式将充电量手动注入,但我似乎找不到解决方法。onActivityResult
Fragment
Intent data
Intent data
我试图在这里设置一个参数,但它没有显示在Intent
我收到的onActivityResult
.
任何人都可以在这里帮我一把吗?
public void requestPayment(BigDecimal amount) {
// Disables the button to prevent multiple clicks.
//mGooglePayButton.setClickable(false);
// The price provided to the API should include taxes and shipping.
// This price is not displayed to the user.
String chargeAmount = amount.divide(MICROS).setScale(2, RoundingMode.HALF_EVEN).toString();
// String price = PaymentsUtil.microsToString(chargeAmount);
TransactionInfo transaction = PaymentsUtil.createTransaction(chargeAmount);
Parcel parcel = Parcel.obtain();
parcel.writeString(chargeAmount);
parcel.recycle();
transaction.writeToParcel(parcel, 0);
PaymentDataRequest request = PaymentsUtil.createPaymentDataRequest(transaction);
Task<PaymentData> futurePaymentData = mPaymentsClient.loadPaymentData(request);
// Since loadPaymentData may show the UI asking the user to select a payment method, we use
// AutoResolveHelper to wait for the user interacting with it. Once completed,
// onActivityResult will be called with the result.
AutoResolveHelper.resolveTask(futurePaymentData, Objects.requireNonNull(getActivity()), LOAD_PAYMENT_DATA_REQUEST_CODE);
}