支付宝

package com.tesy.alipay;

import com.test.alipay.Iservice.Stub;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder; public class PayService extends Service { //[2]我们定义的中间人对象返回
@Override
public IBinder onBind(Intent intent) {
return new MyBinder();
} //支付宝支付的方法
public boolean pay(String name,String pwd,int money){
System.out.println("1验证用户名和密码 ");
System.out.println("2验证手机是否携带病毒");
System.out.println("3调用C语言 做一些加密处理 "); if ("abc".equals(name)&& "123".equals(pwd)&& money <5000) { return true;
}else {
return false; } } //定义中间人对象
private class MyBinder extends Stub{ //调用支付的方法
@Override
public boolean callPay(String name, String pwd, int money) { return pay(name, pwd, money); } } }
       <service android:name="com.itheima.alipay.PayService">
<intent-filter >
<action android:name="com.itheima.alipay"/>
</intent-filter>
</service>

欢乐斗地主买豆

package com.test.ddz;

import com.test.alipay.Iservice;
import com.test.alipay.Iservice.Stub; import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.widget.Toast; public class MainActivity extends Activity { private Myconn conn;
private Iservice iservice; //我们定义的中间人对象 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //[1]调用bindService 获取我们定义的中间人对象
Intent intent = new Intent();
intent.setAction("com.itheima.alipay"); conn = new Myconn();
//[2]绑定服务
bindService(intent, conn, BIND_AUTO_CREATE); } //点击按钮 买豆
public void click(View v) { try {
boolean result = iservice.callPay("abcdd", "123", 100); if (result) {
//支付成功
Toast.makeText(getApplicationContext(), "买豆成功", 1).show();
}else { Toast.makeText(getApplicationContext(), "买豆失败", 1).show();
} } catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} private class Myconn implements ServiceConnection{ @Override
public void onServiceConnected(ComponentName name, IBinder service) {
// 获取中间人对象 iservice = Stub.asInterface(service);
} @Override
public void onServiceDisconnected(ComponentName name) { } } @Override
protected void onDestroy() {
//当Activity销毁的时候 解绑服务
unbindService(conn);
super.onDestroy();
} }

最新文章

  1. 解决echsop兼容jquery(transport.js的冲突)的问题
  2. qt 自动产生 Guid 方法
  3. View的缩放操作--CGAffineTransformMakeScale:
  4. Linux环境下oracle创建和删除表空间及用户
  5. Malloc碎碎念
  6. 解决screen Cannot open your terminal &#39;/dev/pts/1&#39;问题
  7. 一些有用的javascript实例分析(一)
  8. 解决jmeter请求不成功或者报403错误
  9. Hangfire使用ApplicationInsigts监控
  10. VC++6.0连接MySQL数据库(MySQL API)
  11. c/c++ 表达式求值
  12. eos 创建两对的公钥和私钥, 钱包,交易所转账到主网,主网到交易所
  13. Match-----Correlation-----find_ncc_model_exposure
  14. 硬盘img镜像备份工具
  15. Chapter 1 -- UsingAndAvoidingNull
  16. 如何将mysql表结构导出成Excel格式的(并带备注)另附转为word表格的方法
  17. 如何查看Ext自带的API和示例
  18. pshell远程连接服务器
  19. poj 2992 Divisors (素数打表+阶乘因子求解)
  20. Gulp插件使用技巧

热门文章

  1. 教你10分钟对接人大金仓EF Core 6.x
  2. 关于使用JupyterNotebook运行代码运行到一半会闪退的问题
  3. 编写Java程序,使用JDBC连接SQL Server数据库
  4. .NET 编码的基础知识
  5. Postman保存token并使用token的整个流程
  6. Linux中安装java JDK
  7. 简单的sdn防火墙
  8. 新增访客数量MR统计之MR数据输出到MySQL
  9. vue3.0+vite+ts项目搭建--基础配置(二)
  10. JNDI和JDBC的区别