gpt4 book ai didi

android - 不幸的是,应用程序停止了代码名称与 Paypal 集成

转载 作者:行者123 更新时间:2023-11-30 01:16:16 25 4
gpt4 key购买 nike

在原生接口(interface)实现类中编写如下代码:

package com.mycompany.myapp;

import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.content.Intent;
import android.net.Uri;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.R;
import android.widget.Toast;
import android.*;
import android.widget.Toast;
import com.codename1.impl.android.IntentResultListener;
import com.codename1.impl.android.AndroidNativeUtil;
import com.codename1.impl.android.CodenameOneActivity;
//import com.codename1.impl.android.LifecycleListener;
//import com.codename1.impl.android.OnInitListener;
import java.math.BigDecimal;


public class MyNativeImpl{
// private static final String TAG = "paymentdemoblog";
/**
* - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
*
* - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials
* from https://developer.paypal.com
*
* - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires
* without communicating to PayPal's servers.
*/
// private static final String CONFIG_ENVIRONMENT =
// PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;

// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID = "Aeqc2X1rBIEUtDNqsaRNr0h1neFo9QnNmfgmpA3D32uSLaHpGJu9NV1KfMnFmy7O-_hV47I7ST0SXDW2";

private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;

private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));

PayPalPayment thingToBuy;
private static Activity activity() {
return com.codename1.impl.android.AndroidNativeUtil.getActivity();
}


public String payPalTest() {

AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {

public void run() {
Intent intent = new Intent(activity(), PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
activity().startService(intent);
}
});
AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {

public void run() {
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(activity(),
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
activity().startActivityForResult(intent, REQUEST_CODE_PAYMENT);

AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener(){
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toString());
System.out.println(confirm.toString());

Toast.makeText(activity(), "Order placed",
Toast.LENGTH_LONG).show();

} catch (Exception e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {

String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);

sendAuthorizationToServer(auth);
Toast.makeText(activity(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();

} catch (Exception e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
});
}
});

// thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
// "HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
//
// Intent intent = new Intent(activity(),PaymentActivity.class);
//
// intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
// activity().startActivityForResult(intent, REQUEST_CODE_PAYMENT);

//Intent intent=new Intent(Intent.ACTION_VIEW);
//intent.setData(Uri.parse("http://www.javatpoint.com"));
//activity().startActivity(intent);

return "test";
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {

}
public void onDestroy() {


}
public boolean isSupported() {
return false;
}

}

从主类调用:

 MyNative my = (MyNative)NativeLookup.create(MyNative.class);
if(my!= null){
String aa =my.payPalTest();
System.out.println("result::" + aa);
System.out.println("paypalInt" + my.toString());
}

代码构建成功,但是当我尝试从 android 移动设备访问它时,出现错误:

很遗憾已经停止了。如何解决问题

最佳答案

这意味着你有一个未捕获的异常,用电缆连接你的设备并打开 android ddms 来查看跟踪和日志

关于android - 不幸的是,应用程序停止了代码名称与 Paypal 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37814316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com