1

我在我的 monodroid 应用程序中使用 PayPal。我使用了本主题中已经分享的库:http ://forums.xamarin.com/discussion/comment/15331/#Comment_15331

但是我PaymentConfirmation在方法中获取对象时遇到问题OnActivityResult。这是我的代码:

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. 我是否需要任何其他类或代码才能使用数据。GetParcelableExtra?

4

1 回答 1

1

如评论中所写,JavaCast应在这种情况下使用。我认为当为类型生成的绑定不包含GetType方法时会发生这种情况。因此.NET 不知道将其转换为什么。

所以你的线:

PaymentConfirmation pc = (PaymentConfirmation)confirm;

将需要:

PaymentConfirmation pc = confirm.JavaCast<PaymentConfirmation>();
于 2013-10-13T11:46:23.540 回答