这是我的主要活动课程:
package your.in.paypal;
import java.math.BigDecimal;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalActivity;
import com.paypal.android.MEP.PayPalPayment;
public class SimplePayPalIntegration extends Activity implements OnClickListener {
private ViewGroup content;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
invokeSimplePayment();
}
private void invokeSimplePayment(){
try{
PayPal pp = PayPal.getInstance();
if(pp==null)
pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_SANDBOX);
LinearLayout layoutSimplePayment = new LinearLayout(this);
layoutSimplePayment.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);
CheckoutButton launchSimplePayment = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY);
launchSimplePayment.setOnClickListener(this);
layoutSimplePayment.addView(launchSimplePayment);
setContentView(layoutSimplePayment);
}catch(Exception e)
{
e.printStackTrace();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(resultCode) {
case Activity.RESULT_OK:
Log.d("", "RESULT_OK");
break;
case Activity.RESULT_CANCELED:
Log.d("", "RESULT_CANCELED");
break;
case PayPalActivity.RESULT_FAILURE:
Log.d("", "RESULT_FAILURE");
break;
}
}
@Override
public void onClick(View v) {
PayPalPayment payment = new PayPalPayment();
payment.setSubtotal(new BigDecimal("8.25"));
payment.setCurrencyType("USD");
payment.setRecipient("mymail@gmail.com");
payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
startActivityForResult(checkoutIntent, 1);
Log.d("", "clicked");
}
}
这是我的AndroidManifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.in.paypal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<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"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SimplePayPalIntegration"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.paypal.android.MEP.PayPalActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|orientation"/>
</application>
我已经将 The 添加PayPal_MPL.jar
到项目中。当我运行项目时,我成功地转到了 paypal 按钮,当我单击该按钮时,我得到了登录页面,但是当我输入沙箱登录 ID 和密码时,我得到了错误Login failed. Please try again.
,为什么?请告诉我我做错了什么。