需要支付的应用
- 把刚才定义好的aidl文件拷贝过来,注意aidl文件所在的包名必须跟原包名一致
- 远程绑定支付宝的服务,通过onServiceConnected方法我们可以拿到中间人对象
- 把中间人对象通过Stub.asInterface方法强转成定义了pay方法的接口
- 调用中间人的pay方法
PayInterface.aidl
interface PayInterface {
void pay();
}
PayService.java
public class PayService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return new PayPangZhi();
}
//中间人对象
class PayPangZhi extends Stub{
@Override
public void pay() throws RemoteException {
// 调用服务的pay方法
PayService.this.pay();
}
}
public void pay(){
System.out.println("检测运行环境");
System.out.println("加密用户名密码");
System.out.println("建立连接");
System.out.println("上传数据");
System.out.println("完成支付");
}
}
AndroidManifest.xml
<service android:name="com.exp.alipay.PayService">
<intent-filter >
<action android:name="com.exp.pangzhi"/>
</intent-filter>
</service>