【问题标题】:Paypal Integration for payments in Android用于 Android 支付的 Paypal 集成
【发布时间】:2015-06-25 22:28:58
【问题描述】:

我正在尝试将 paypal 作为付款方式集成到我的 android 应用程序中,但我因类似这样的错误而失败。

错误:(70, 5) 错误: 找不到合适的方法 startService(Intent,int) 方法 ContextWrapper.startService(Intent) 是 不适用(实际参数列表和形式参数列表的长度不同) 方法 Context.startService(Intent) 不适用(实际和 形式参数列表的长度不同)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay);
        actionBar = getActionBar();
        ColorDrawable colorDrawable = new ColorDrawable(
                Color.parseColor("#01bfff"));
        actionBar.setBackgroundDrawable(colorDrawable);
        btnPayPal = (Button) findViewById(R.id.btnPaypal);

        //Intent get value
        Intent intent = getIntent();
        final String currency = intent.getStringExtra("CURRENCY");
        int cost = intent.getIntExtra("COST", 0);
        txtCurrency.setText(currency);
        txtTotal.setText(String.valueOf(" " + cost));

        btnPayPal.setOnClickListener(new OnClickListener() {

public void onClick (View v) {
    Intent in = new Intent(this, PayPalService.class);
    in.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

    startService(intent,0);
}public void onBuyPressed(View pressed) {

     PayPalPayment payment = new PayPalPayment(new BigDecimal("2"), "USD", "Total Ticket Price : ",
             PayPalPayment.PAYMENT_INTENT_SALE);

     Intent intnt = new Intent(this, PaymentActivity.class);
    intnt.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

     intnt.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

     startActivityForResult(intnt, 0);
 }
 @Override
           protected void onActivityResult (int requestCode, int resultCode, Intent data) {
               if (resultCode == Activity.RESULT_OK) {
                   PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                   if (confirm != null) {
                       try {
                           Log.i("paymentExample", confirm.toJSONObject().toString(4));




                       } catch (JSONException e) {
                           Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                       }
                   }
               }
               else if (resultCode == Activity.RESULT_CANCELED) {
                   Log.i("paymentExample", "The user canceled.");
               }
               else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                   Log.i("paymentExample", "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
               }
           }

        });

它在

中返回预期
public void onClick (View v) {
Intent in = new Intent(this, PayPalService.class);
in.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

startService(intent,0);

}

【问题讨论】:

    标签: android android-intent paypal


    【解决方案1】:

    你在这里做错了

    startService(intent,0);
    

    改成

    startService(intent);
    

    startService(Intent) 只有一个参数。

    更多信息请参考Official Service Docs

    【讨论】:

    • 遇到此错误 :: 没有找到适合 Intent(,Class) 构造函数的合适构造函数 Intent.Intent(String,Uri,Context,Class>) 不适用。
    • @RajanKandel 做Intent in = new Intent(YourActivity.this, PayPalService.class);
    猜你喜欢
    • 2011-11-11
    • 2020-05-21
    • 2014-04-10
    • 1970-01-01
    • 2015-09-02
    • 2013-08-23
    • 2021-04-26
    • 2023-01-18
    • 2011-09-06
    相关资源
    最近更新 更多