首页 技术 正文
技术 2022年11月16日
0 收藏 842 点赞 4,903 浏览 4185 个字
/********************************************************************************
* Android AIDL自动生成Java文件测试
* 说明:
* 知道有aidl这东西已经挺久了,但是一直没有花时间来系统了解一下其工作机制,现在
* 花点时间一点一点验证一下其功能。
*
* 2016-5-8 深圳 南山平山村 曾剑锋
*******************************************************************************/一、参考文章:
. Android AIDL使用详解
http://blog.csdn.net/stonecao/article/details/6425019
. android进程间通信:使用AIDL
http://blog.csdn.net/saintswordsman/article/details/5130947二、cat forService.aidl
package com.example.aidltest.aidl; import com.example.aidltest.aidl.forActivity; interface forService {
void registerTestCall(forActivity cb);
void invokCallBack();
}三、cat forService.java
/*
* This file is auto-generated. DO NOT MODIFY.
* Original file: D:\\soft\\Android\\workspace\\AidlTest\\src\\com\\example\\aidltest\\aidl\\forService.aidl
*/
package com.example.aidltest.aidl; // 继承了android.os.IInterface接口
public interface forService extends android.os.IInterface {
/** Local-side IPC implementation stub class. */
// Stub类继承了Binder,并继承我们在aidl文件中定义的接口
public static abstract class Stub extends android.os.Binder implements
com.example.aidltest.aidl.forService {
private static final java.lang.String DESCRIPTOR = "com.example.aidltest.aidl.forService"; /** Construct the stub at attach it to the interface. */
public Stub() {
this.attachInterface(this, DESCRIPTOR);
} /**
* Cast an IBinder object into an com.example.aidltest.aidl.forService
* interface, generating a proxy if needed.
*/
// 在使用的时候经常会看到这一部分的内容
public static com.example.aidltest.aidl.forService asInterface(
android.os.IBinder obj) {
if ((obj == null)) {
return null;
}
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
if (((iin != null) && (iin instanceof com.example.aidltest.aidl.forService))) {
return ((com.example.aidltest.aidl.forService) iin);
}
return new com.example.aidltest.aidl.forService.Stub.Proxy(obj);
} @Override
public android.os.IBinder asBinder() {
return this;
} @Override
public boolean onTransact(int code, android.os.Parcel data,
android.os.Parcel reply, int flags)
throws android.os.RemoteException {
switch (code) {
case INTERFACE_TRANSACTION: {
reply.writeString(DESCRIPTOR);
return true;
}
case TRANSACTION_registerTestCall: {
data.enforceInterface(DESCRIPTOR);
com.example.aidltest.aidl.forActivity _arg0;
_arg0 = com.example.aidltest.aidl.forActivity.Stub
.asInterface(data.readStrongBinder());
this.registerTestCall(_arg0);
reply.writeNoException();
return true;
}
case TRANSACTION_invokCallBack: {
data.enforceInterface(DESCRIPTOR);
this.invokCallBack();
reply.writeNoException();
return true;
}
}
return super.onTransact(code, data, reply, flags);
} private static class Proxy implements
com.example.aidltest.aidl.forService {
private android.os.IBinder mRemote; Proxy(android.os.IBinder remote) {
mRemote = remote;
} @Override
public android.os.IBinder asBinder() {
return mRemote;
} public java.lang.String getInterfaceDescriptor() {
return DESCRIPTOR;
} @Override
public void registerTestCall(
com.example.aidltest.aidl.forActivity cb)
throws android.os.RemoteException {
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeStrongBinder((((cb != null)) ? (cb.asBinder())
: (null)));
mRemote.transact(Stub.TRANSACTION_registerTestCall, _data,
_reply, );
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
} @Override
public void invokCallBack() throws android.os.RemoteException {
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
mRemote.transact(Stub.TRANSACTION_invokCallBack, _data,
_reply, );
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}
} static final int TRANSACTION_registerTestCall = (android.os.IBinder.FIRST_CALL_TRANSACTION + );
static final int TRANSACTION_invokCallBack = (android.os.IBinder.FIRST_CALL_TRANSACTION + );
} // AIDL中自定义的方法,没有实现
public void registerTestCall(com.example.aidltest.aidl.forActivity cb)
throws android.os.RemoteException; public void invokCallBack() throws android.os.RemoteException;
}四、cat MainActivity.java
public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
......
new forService.Stub() { @Override
public void registerTestCall(forActivity cb) throws RemoteException {
// TODO Auto-generated method stub } @Override
public void invokCallBack() throws RemoteException {
// TODO Auto-generated method stub }
};
......
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902