果然是因为leancloud没有支付功能
1 AndroidManifest.xml中
加入 如下代码:
(1)
<pre><code><activity
android:name="c.b.a.A"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="c.b.a.B"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent" /></code></pre>
(2)
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
然后在 activity中加入bmob的appid:
String APPID = "ID";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BP.init(this, APPID);
tv = (TextView)findViewById(R.id.textview);
order = (TextView)findViewById(R.id.order);
payByAli();
}
// 调用支付宝支付
void payByAli() {
//showDialog("正在获取订单...");
final String name = "name";
tv.append("正在获取订单...");
// BmobPay.init(this, APPID);
BP.pay(this, name, "body", 0.02, true, new PListener() {
// 因为网络等原因,支付结果未知(小概率事件),出于保险起见稍后手动查询
@Override
public void unknow() {
Toast.makeText(MainActivity.this, "支付结果未知,请稍后手动查询",
Toast.LENGTH_SHORT).show();
tv.append(name + "'s pay status is unknow\n\n");
//hideDialog();
}
// 支付成功,如果金额较大请手动查询确认
@Override
public void succeed() {
Toast.makeText(MainActivity.this, "支付成功!", Toast.LENGTH_SHORT)
.show();
tv.append(name + "'s pay status is success\n\n");
//hideDialog();
}
// 无论成功与否,返回订单号
@Override
public void orderId(String orderId) {
// 此处应该保存订单号,比如保存进数据库等,以便以后查询
order.setText(orderId);
tv.append(name + "'s orderid is " + orderId + "\n\n");
//showDialog("获取订单成功!请等待跳转到支付页面~");
}
// 支付失败,原因可能是用户中断支付操作,也可能是网络原因
@Override
public void fail(int code, String reason) {
Toast.makeText(MainActivity.this, "支付中断!", Toast.LENGTH_SHORT)
.show();
tv.append(name + "'s pay status is fail, error code is " + code
+ " ,reason is " + reason + "\n\n");
//hideDialog();
}
});
}