需要在新线程中调用支付接口。(可参考alipay_demo实现)
获取PayTask支付对象调用支付(支付或者授权的行为需要在独立的非ui线程中执行),代码示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | final String orderInfo = info; // 订单信息 Runnable payRunnable = new Runnable() { @Override public void run() { PayTask alipay = new PayTask(DemoActivity. this ); String result = alipay.pay(orderInfo, true ); Message msg = new Message(); msg.what = SDK_PAY_FLAG; msg.obj = result; mHandler.sendMessage(msg); } }; // 必须异步调用 Thread payThread = new Thread(payRunnable); payThread.start(); |