采用aidl访问远程服务里面的方法
来源:互联网 发布:同性约会软件 编辑:程序博客网 时间:2024/06/05 17:59
一个应用程序一个进程里面 定义一个IService的接口来描述方法
如果我们要调用另一个进程服务里面的方法 aidl
(android interface definatioin language)
首先我们定义一个aidl接口
把所有的修饰符去掉。
IService.aidl
package org.china.lee.server;interface IService {void callMethodService();}
服务接口
package org.china.lee.server;import android.app.Service;import android.content.Intent;import android.os.IBinder;import android.os.RemoteException;public class RemoteServer extends Service {@Overridepublic IBinder onBind(Intent intent) {return new MyBinder();}private class MyBinder extends IService.Stub{@Overridepublic void callMethodService() throws RemoteException {sayHelloInService();}}private void sayHelloInService() {System.out.println("Hello In Service");}@Overridepublic void onCreate() {System.out.println("**** onCreate()");super.onCreate();}@Overridepublic void onDestroy() {System.out.println("**** onDestroy()");super.onDestroy();}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {System.out.println("**** onStartCommand()");return super.onStartCommand(intent, flags, startId);}}
Activity
package org.china.lee.aidldemo;import org.china.lee.server.IService;import android.app.Activity;import android.content.ComponentName;import android.content.Intent;import android.content.ServiceConnection;import android.os.Bundle;import android.os.IBinder;import android.os.RemoteException;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class AidlActivity extends Activity {private Button btn;private IService iService;private class MyConn implements ServiceConnection{@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {iService=IService.Stub.asInterface(service);}@Overridepublic void onServiceDisconnected(ComponentName name) {}}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.activity_aidl);Intent intent=new Intent();intent.setAction("org.china.lee.server.RemoteServer");bindService(intent,new MyConn(),BIND_AUTO_CREATE);btn=(Button) super.findViewById(R.id.btn);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {try {iService.callMethodService();} catch (RemoteException e) {e.printStackTrace();}}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.aidl, menu);return true;}}
系统清单文件配置
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.china.lee.aidldemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="org.china.lee.aidldemo.AidlActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="org.china.lee.server.RemoteServer" > <intent-filter > <action android:name="org.china.lee.server.RemoteServer"/> </intent-filter> </service> </application></manifest>
0 0
- 采用aidl技术去访问远程服务里面的方法
- 采用aidl访问远程服务里面的方法
- 采用aidl绑定远程服务
- 采用AIDL调用远程服务
- android,aidl,绑定远程服务,调用远程服务的方法
- Android 采用AIDL绑定远程服务
- android-------采用AIDL调用远程服务
- Android_08_用AIDL访问远程服务中的方法
- 进程间的通信AIDL与远程服务的访问
- AIDL跨进程通讯访问远程服务
- 访问本地服务里面的方法
- 91_采用绑定服务的方式调用服务里面的方法
- 绑定远程服务的流程aidl
- android 的aidl绑定远程服务
- aidl远程服务调用
- AIDL绑定远程服务
- aidl绑定远程服务
- Service (aidl远程服务)
- 2013级Java第1周(春)项目——一个简单的考勤签到程序
- 跨库操作导致mysql主从复制中断
- 编写安全代码——不要用memcmp比较structure
- 自定义createElement——根据html字符串创建元素
- 函数内使用指针
- 采用aidl访问远程服务里面的方法
- Ubuntu下无法启动Eclipse的原因
- Qt下的跨目录多工程编译
- C#中的并行与多线程编程
- Linux0.12内核读书笔记
- jackson json 简单入门
- Html5游戏开发攻略(API篇)
- Ubuntu12.04搭建Hadoop环境
- qmake使用实践:包含动态库的Qt4工程