import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AIDLClient extends Activity {
  private ICat catService;
  private Button get;
  EditText color;
  EditText weight;
  private ServiceConnection conn = new ServiceConnection() {

    @Override
    public void onServiceDisconnected(ComponentName name) {
      catService = null;

    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
      //获取远程Service的onBind方法返回的对象的代理
      catService = ICat.Stub.asInterface(service);
    }
  };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_aidlclient);
    get = (Button) findViewById(R.id.get);
    color = (EditText) findViewById(R.id.color);
    weight = (EditText) findViewById(R.id.weight);
    //创建所需绑定服务的Intent
    Intent intent = new Intent();
    intent.setAction("mediaprovider.action.AIDL_SERVICE");
    //绑定远程服务
    bindService(intent, conn, Service.BIND_AUTO_CREATE);
    get.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        try {
          // 获取并显示远程Service的状态
          color.setText(catService.getColor());
          weight.setText(catService.getWeight()+"");
        } catch (RemoteException e) {
          e.printStackTrace();
        }
        }
    });
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    //解除绑定
    this.unbindService(conn);
  }

}

客户端访问AIDLService(远程绑定Service)的更多相关文章

  1. 使用AIDL将接口暴露给客户端(远程绑定Service)

    import java.util.Timer;import java.util.TimerTask; import jww.mediaprovidertest.ICat.Stub;import and ...

  2. [原创]用windows7连接windows2003的终端服务器时,出现"由于这台计算机没有远程桌面客户端访问许可证,远程会话被中断"的问题

    用windows7连接windows2003的终端服务器时,出现"由于这台计算机没有远程桌面客户端访问许可证,远程会话被中断"的问题,原因是终端服务器授权方式设置为了"每 ...

  3. Linux 安装MongoDB 并设置防火墙,使用远程客户端访问

    1. 下载 MongoDB 提供了 linux 各发行版本 64 位的安装包  下载地址:https://www.mongodb.com/download-center#community 2. 安装 ...

  4. 在Centos下搭建git并可以通过windows客户端访问

    亲测在本地虚拟机和远程服务器上无问题,如有不懂请留言. 注意事项:以下所有操作是在root权限下操作的.1.Centos服务器版本centos6.5 2.首先安装git,使用yum在线安装 yum i ...

  5. Android中AIDL的理解与使用(二)——跨应用绑定Service并通信

    跨应用绑定Service并通信: 1.(StartServiceFromAnotherApp)AIDL文件中新增接口: void setData(String data); AppService文件中 ...

  6. python socket 套接字编程 单进程服务器 实现多客户端访问

    服务器: import socket #单进程服务器 实现多客户端访问 IO复用 #吧所有的客户端套接字 放在一个列表里面,一次又一次的便利过滤 server = socket.socket(sock ...

  7. Android:(本地、可通信的、前台、远程)Service使用全面介绍

    2.具体使用解析 2.1 本地Service 这是最普通.最常用的后台服务Service. 2.1.1 使用步骤 步骤1:新建子类继承Service类 需重写父类的onCreate().onStart ...

  8. Linux Samba目录服务搭建与Java客户端访问

    前言: 本文比较简略,只求快速入门,若要了解详情,推荐一篇文章:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html 1,安装sa ...

  9. 获取客户端访问真实 IP

    转载自:https://www.qikqiak.com/post/get-client-realip/ 通常,当集群内的客户端连接到服务的时候,是支持服务的 Pod 可以获取到客户端的 IP 地址的, ...

随机推荐

  1. linux安装phpstorm出现 Startup Error: Unable to detect graphics environment

    在centos6.2下在安装phpstorm下遇到 Startup Error: Unable to detect graphics environment 其中jdk安装的版本是 1.7.0_79  ...

  2. THE SENSE OF BEAUTY

    #include<stdio.h> int main() { ][] = { " ,.:;j", " ,: i. .,:;ff", " : ...

  3. [转载] goroutine背后的系统知识

    原文: http://www.sizeofvoid.net/goroutine-under-the-hood/ 文章写的非常好, 对内部原理解释的非常清楚, 是我喜欢的风格, 感谢作者的精彩文章. = ...

  4. JavaScript的严格模式

    js除了在普通的常规模式,ECMAscript 5添加了第二种运行模式:"严格模式"(strict mode).严格模式支持IE9+ Chrome FireFox 等主流浏览器. ...

  5. view的封装

    如果一个view内部的子控件比较多,一般会考虑自定义一个view,把它内部子控件的创建屏蔽起来,不让外界关心 外界可以传入对应的模型数据给view,view拿到模型数据后给内部的子控件设置对应的数据 ...

  6. 如何让Service自动重启而不被kill掉

    重写service的onStartCommand方法. @Override    public int onStartCommand(Intent intent, int flags, int sta ...

  7. Linq To Sql 语法 子查询 & In & Join

    子查询 描述:查询订单数超过5的顾客信息 查询句法: var 子查询 =from cin ctx.Customers                    where                  ...

  8. LinuxShell脚本攻略--第八章 当个好管家

    监视磁盘的使用情况 $ du file1.txt file2.txt $ du -a file_or_dir #-a递归输出指定目录的所有文件统计 $ du file_or_dir #这只是显示子目录 ...

  9. SAP中寄售处理

    寄售分两种: 1, 供应商提供货物,我们销售 2,我们提供货物,寄售商销售 [@more@] 1, 供应商提供货物,我们销售 创建PO,购买寄售货物,categories维护成K,然后收货即可. 2, ...

  10. Lecture Notes: Macros

    原论文链接失效,特在这里保存一份 http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html Lisp functions take Lisp values ...