Java 如何在android集成中使用MECL设置Paypal中的商户帐户id?

Java 如何在android集成中使用MECL设置Paypal中的商户帐户id?,java,android,paypal,paypal-sandbox,Java,Android,Paypal,Paypal Sandbox,我想做一个贝宝集成的示例代码。 它已经做了,但我不明白我需要把商人帐户Id的代码。我有卖家Id和商人Id,但我不知道我想把这个放在哪里 商人身份证。所以请任何一个布迪帮我 package com.paypal.android.pizza; import java.util.Vector; import android.app.Activity; import android.app.ProgressDialog; import android.os.B

我想做一个贝宝集成的示例代码。 它已经做了,但我不明白我需要把商人帐户Id的代码。我有卖家Id和商人Id,但我不知道我想把这个放在哪里 商人身份证。所以请任何一个布迪帮我

    package com.paypal.android.pizza;

    import java.util.Vector;

    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.KeyEvent;
    import android.view.View;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;

    import com.paypal.android.MECL.PayPal;

    public class Pizza extends Activity {

        // The instance of our activity
        private static Pizza _instance;

        // The reference token that we get from initializing the MECL library
        public static String _deviceReferenceToken;

        // The PayPal server to be used - can also be ENV_NONE and ENV_LIVE
        private static final int server = PayPal.ENV_SANDBOX;
        // The ID of your application that you received from PayPal
        private static final String appID = "APP-80W284485P519543T";

        public static final String build = "11.01.04.8174";

        // The possible results from initializing MECL
        protected static final int INITIALIZE_SUCCESS = 0;
        protected static final int INITIALIZE_FAILURE = 1;

        // The pages of our application
        public static final int PAGE_HOME = 0;
        public static final int PAGE_CUSTOMIZE = 1;
        public static final int PAGE_FINALIZE = 2;
        public static final int PAGE_WEB = 3;

        // The currently shown page
        private BasePage currentPage;

        // The pizza sizes
        public static final int SIZE_SMALL = 0;
        public static final int SIZE_MEDIUM = 1;
        public static final int SIZE_LARGE = 2;

        // The pizza toppings
        public static final int TOPPING_EXTRA_CHEESE = 0;
        public static final int TOPPING_PEPPERONI = 1;
        public static final int TOPPING_MUSHROOMS = 2;
        public static final int TOPPING_ONIONS = 3;

        // The pizza acquiring methods
        public static final int METHOD_PICKUP = 0;
        public static final int METHOD_DELIVERY = 1;

        // Our current selections that are given defaults to start
        private int currentSize = SIZE_SMALL;
        private Vector<Integer> currentToppings = new Vector<Integer>();
        private int currentCount = 1;
        private int currentMethod = METHOD_PICKUP;

        // The WebView that we'll use to display MECL
        private WebView _webView;

        // The popup we'll use to show loading when initializing the library
        private ProgressDialog mProgDialog;

        // This handler will allow us to properly update the UI. You cannot touch
        // Views from a non-UI thread.
        Handler hRefresh = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case INITIALIZE_SUCCESS:
                    // We have initialized the application, close the dialog and
                    // launch the WebView
                    mProgDialog.cancel();
                    launchWeb();
                    break;
                case INITIALIZE_FAILURE:
                    // Initialization failure, close the dialog, update the page and
                    // show a toast
                    mProgDialog.cancel();
                    currentPage.update();
                    Toast.makeText(Pizza.getInstance(),
                            "Failed to initialize PayPal", Toast.LENGTH_SHORT)
                            .show();
                    break;
                }
            }
        };

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Set the instance
            _instance = this;

            // Set our defaults
            currentSize = SIZE_SMALL;
            currentToppings = new Vector<Integer>();
            currentCount = 1;
            currentMethod = METHOD_PICKUP;

            // Set our page
            currentPage = new HomePage(this);
            setContentView(currentPage);
        }

        /*
         * This method will be used every time we want to change the page
         */
        public void changePage(int page) {
            switch (page) {
            case PAGE_HOME:
                // Change to the home page
                currentPage = new HomePage(this);
                setContentView(currentPage);
                break;
            case PAGE_CUSTOMIZE:
                // Change to the customize page
                currentPage = new CustomizePage(this);
                setContentView(currentPage);
                break;
            case PAGE_FINALIZE:
                // Change to the finalize page
                currentPage = new FinalizePage(this);
                setContentView(currentPage);
                break;
            case PAGE_WEB:
                // Time to launch the library but first we need to initialize

                // Show the loading popup
                mProgDialog = ProgressDialog.show(this, "", "Loading");

                // Create a separate thread to do the initialization
                Thread libraryInitializationThread = new Thread() {
                    public void run() {
                        // Initialize the library
                        initLibrary();

                        // The library is initialized so let's launch it by
                        // notifying our handler
                        if (PayPal.getInstance().isLibraryInitialized()) {
                            hRefresh.sendEmptyMessage(INITIALIZE_SUCCESS);
                        } else {
                            hRefresh.sendEmptyMessage(INITIALIZE_FAILURE);
                        }
                    }
                };
                libraryInitializationThread.start();
                break;
            }
        }

        private void initLibrary() {
            // This is the main initialization call that takes in your Context, the
            // Application ID, the server you would like to connect to, and your
            // PayPalListener
            PayPal.fetchDeviceReferenceTokenWithAppID(this, appID, server,
                    new ResultDelegate());

            // -- These are required settings.
            PayPal.getInstance().setLanguage("en_US"); // Sets the language for the
                                                        // library.


        }

        private void launchWeb() {
            // Setup the url for our pizza app to connect to
            String buf = new String(
                    "http://paydemo.sms4me.com/ECDemo-server/cart.jsp?");
            buf += "delivery="
                    + (currentMethod == METHOD_PICKUP ? "false" : "true");
            buf += "&count=" + currentCount;
            String size = new String("Small");
            if (currentSize == SIZE_MEDIUM)
                size = "Medium";
            else if (currentSize == SIZE_LARGE)
                size = "Large";
            buf += "&size=" + size;
            if (currentToppings.size() > 0) {
                buf += "&toppings=";
                for (int i = 0; i < currentToppings.size(); i++) {
                    if (i != 0)
                        buf += ",";
                    String topping = "Extra%20Cheese";
                    if (currentToppings.elementAt(i) == TOPPING_PEPPERONI)
                        topping = "Pepperoni";
                    else if (currentToppings.elementAt(i) == TOPPING_MUSHROOMS)
                        topping = "Mushrooms";
                    else if (currentToppings.elementAt(i) == TOPPING_ONIONS)
                        topping = "Onions";
                    buf += topping;
                }
            }
            buf += "&drt=" + _deviceReferenceToken;

            android.util.Log.d("PIZZA_REQUEST", buf.replaceAll("&", "\n&"));

            // Construct the WebView
            _webView = new WebView(this);

            // Set our view to the WebView
            _webView.getSettings().setJavaScriptEnabled(true);
            setContentView(_webView);

            // Setup a WebViewClient so we know when the url changes
            _webView.setWebViewClient(new WebViewClient() {
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // Our servlet only uses one url for both success or failure
                    if (url.equals("http://paydemo.sms4me.com/ECDemo-server/cancel.html")) {
                        // The url was hit so it's time to go back to our home page
                        changePage(PAGE_HOME);
                        return true;
                    }
                    return false;
                }
            });

            // Load our url
            _webView.loadUrl(buf);

            // The android WebView sometimes does not have focus and this affects
            // different UI elements so we'll force the focus to work around this
            _webView.requestFocus(View.FOCUS_DOWN);
        }

        public static Pizza getInstance() {
            return _instance;
        }

        public int getCurrentSize() {
            return currentSize;
        }

        public void setCurrentSize(int currentSize) {
            this.currentSize = currentSize;
        }

        public Vector<Integer> getCurrentToppings() {
            return currentToppings;
        }

        public void setCurrentToppings(Vector<Integer> currentToppings) {
            this.currentToppings = currentToppings;
        }

        public int getCurrentCount() {
            return currentCount;
        }

        public void setCurrentCount(int currentCount) {
            this.currentCount = currentCount;
        }

        public int getCurrentMethod() {
            return currentMethod;
        }

        public void setCurrentMethod(int currentMethod) {
            this.currentMethod = currentMethod;
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            // We need to manually handle the back key for WebView
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (_webView != null && _webView.canGoBack()) {
                    // It's the WebView and we can navigate back with it so let's do
                    // so
                    _webView.goBack();
                    return true;
                } else if (_webView != null) {
                    // It's the WebView but we can't navigate back, so let's go to
                    // the pizza home page
                    changePage(PAGE_HOME);
                    _webView = null;
                    return true;
                } else {
                    // It's not the WebView so let's save the values and move back a
                    // page
                    if (currentPage instanceof CustomizePage) {
                        currentPage.saveValues();
                        changePage(PAGE_HOME);
                    } else if (currentPage instanceof FinalizePage) {
                        currentPage.saveValues();
                        changePage(PAGE_CUSTOMIZE);
                    }
                    return true;
                }
            }
            return super.onKeyDown(keyCode, event);
        }
    }
package com.paypal.android.pizza;
导入java.util.Vector;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.os.Bundle;
导入android.os.Handler;
导入android.os.Message;
导入android.view.KeyEvent;
导入android.view.view;
导入android.webkit.WebView;
导入android.webkit.WebViewClient;
导入android.widget.Toast;
导入com.paypal.android.MECL.paypal;
公营比萨饼推广活动{
//我们活动的实例
私有静态Pizza_实例;
//我们从初始化MECL库中获得的引用令牌
公共静态字符串_deviceReferenceToken;
//要使用的贝宝服务器-也可以是ENV_NONE和ENV_LIVE
私有静态final int server=PayPal.ENV_SANDBOX;
//从PayPal收到的应用程序ID
私有静态最终字符串appID=“APP-80W284485P519543T”;
公共静态最终字符串构建=“11.01.04.8174”;
//初始化MECL的可能结果
受保护的静态最终int初始化_成功=0;
受保护的静态最终int初始化_故障=1;
//我们申请的页面
公共静态最终整型页面_HOME=0;
公共静态最终整型页面_CUSTOMIZE=1;
公共静态最终整型页面_FINALIZE=2;
公共静态最终整版页面_WEB=3;
//当前显示的页面
私有基页当前页;
//比萨饼的尺寸
公共静态最终整数大小_SMALL=0;
公共静态最终整数大小_MEDIUM=1;
公共静态最终整数大小_LARGE=2;
//比萨配料
公共静态最终int TOPPING_EXTRA_CHEESE=0;
公共静态最终int TOPPING_PEPPERONI=1;
公共静态最终int-TOPPING_=2;
公共静态最终整型浇头洋葱=3;
//比萨饼的获取方法
公共静态最终整数方法\u拾取=0;
公共静态最终整数方法_交付=1;
//我们当前的选择默认为开始
private int currentSize=SIZE\u SMALL;
私有向量currentToppings=新向量();
私有int currentCount=1;
private int currentMethod=方法\拾取;
//我们将用于显示MECL的WebView
私有网络视图_网络视图;
//初始化库时用于显示加载的弹出窗口
私人ProgressDialog;
//此处理程序将允许我们正确更新UI。您不能触摸
//来自非UI线程的视图。
Handler hRefresh=new Handler(){
@凌驾
公共无效handleMessage(消息消息消息){
开关(msg.what){
成功案例:
//我们已经初始化了应用程序,关闭对话框并
//启动WebView
mProgDialog.cancel();
启动Web();
打破
案例初始化失败:
//初始化失败,关闭对话框,更新页面并
//举杯
mProgDialog.cancel();
currentPage.update();
Toast.makeText(Pizza.getInstance(),
“未能初始化PayPal”,Toast.LENGTH\u SHORT)
.show();
打破
}
}
};
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//设置实例
_实例=此;
//设置默认值
currentSize=SIZE\u SMALL;
currentToppings=新向量();
currentCount=1;
currentMethod=方法\拾取;
//设置我们的页面
currentPage=新主页(本页);
setContentView(当前页面);
}
/*
*每次我们想要更改页面时都将使用此方法
*/
公共无效更改页(整版页){
交换机(第页){
案例首页:
//更改到主页
currentPage=新主页(本页);
setContentView(当前页面);
打破
案例页面\u自定义:
//更改到“自定义”页面
currentPage=新自定义页(此页);
setContentView(当前页面);
打破
案例页面_最终确定:
//更改为“完成”页面
currentPage=新的终结页(本页);
setContentView(当前页面);
打破
个案网页(网址:
//启动库的时间到了,但首先我们需要初始化
//显示加载弹出窗口
mProgDialog=ProgressDialog.show(此为“,”正在加载“);
//创建一个单独的线程来进行初始化
线程库初始化线程=新线程(){
公开募捐{
//初始化库
initLibrary();
//库已初始化,因此让我们通过
//通知我们的处理人
if(PayPal.getInstance().isLibraryInitialized()){
hRefresh.sendEmptyMessage(初始化