以下显示我的代码用于在我的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();
}
}
};
答案 0 :(得分:2)
如果你已经添加了jar文件但是没有正确包含这种类型的错误。请点击你的项目,然后转到属性 - java build path - order and export。检查jar旁边是否有复选框。应该检查它。再次运行您的应用程序并检查是否存在相同的问题。
答案 1 :(得分:1)
也许您忘记将此权限放在AndroidManifest.xml上
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>