我在我的 monodroid 应用程序中使用 PayPal。我使用了本主题中共享的库:http://forums.xamarin.com/discussion/comment/15331/#Comment_15331
但是我在 OnActivityResult
方法中获取 PaymentConfirmation
对象时遇到问题。这是我的代码:
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Ok ) {
var confirm = data.GetParcelableExtra ("com.paypal.android.sdk.paymentConfirmation") ;
PaymentConfirmation pc = (PaymentConfirmation)confirm;
if (confirm != null) {
try {
//Log.Info ("paymentExample", confirm.ToJSONObject ().ToString (4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.\
} catch (JSONException e) {
Log.Error ("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}else if (resultCode == Result.Canceled ) {
Log.Info ("paymentExample", "The user canceled.");
}else {
Log.Info ("paymentExample", "An invalid payment was submitted. Please see the docs.");
}
}
在方法的第三行。编译器无法将确认转换为 PaymentConfirmation
。我是否需要任何其他类或代码才能使用 data.GetParcelableExtra
?
最佳答案
如评论中所述,在这种情况下应使用 JavaCast
。我认为当为类型生成的绑定(bind)不包含 GetType
方法时会发生这种情况。因此 .NET 不知道将其转换为什么。
所以你的台词:
PaymentConfirmation pc = (PaymentConfirmation)confirm;
将需要:
PaymentConfirmation pc = confirm.JavaCast<PaymentConfirmation>();
关于android - 从 PayPal lib 获取支付配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19333406/