这是可能由于PayPal SDK版本过低或SDK的初始化失败导致的。建议检查PayPal SDK的版本和初始化是否正确。
以下是一个示例代码,演示如何正确初始化PayPal SDK以及在Android应用中使用Paypal原生结账按钮:
allprojects { repositories { google() jcenter() // Add the following lines maven { url "https://paypal.bintray.com/PayPal-Android-SDK" } } }
dependencies { implementation 'com.paypal.sdk:paypal-android-sdk:2.15.3' }
private void initPayPalSDK() { PayPalConfiguration config = new PayPalConfiguration() .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX) .clientId("Your-Client-ID");
PayPalPaymentIntent paymentIntent = PayPalPaymentIntent.SALE;
String currencyCode = "USD";
PayPalItem item = new PayPalItem("Item", 1, new BigDecimal("0.01"), currencyCode, "sku001");
Intent intent = new Intent(getActivity(), PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);
}
@Override public void onStart() { super.onStart(); Intent intent = new Intent(getActivity(), PayPalService.class); intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config); getActivity().startService(intent); }
@Override public void onStop() { super.onStop(); getActivity().stopService