下面显示了我用于在我的 android 应用程序中初始化 paypal 对象的代码。运行时错误是由 doInBackground() 引起的,所以我认为这可能是由于 payPal.isLibraryInitialized() 返回的错误。
你们有在 android 应用程序中集成 paypal 的经验吗?
private class PayPalInitializer extends AsyncTask<Void, Void, Boolean> {
private static final String APP_ID = "APP-80W284485P519543T";
private Context mContext;
private ProgressDialog mProgressDialog;
public PayPalInitializer(Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setMessage("...");
mProgressDialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
boolean success = false;
PayPal payPal = PayPal.getInstance();
if (payPal == null) {
payPal = PayPal.initWithAppID(mContext, APP_ID, PayPal.ENV_SANDBOX);
payPal.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// Set to true if the transaction will require shipping.
payPal.setShippingEnabled(true);
if (payPal.isLibraryInitialized()) {
success = true;
}
}
return success;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
mProgressDialog.hide();
mProgressDialog = null;
if (result) {
setupButton();
} else {
Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
}
}
};