//返回给客户端
reply.writeString(“服务器接受数据成功”);
reply.writeInt(200);
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return super.onTransact(code, data, reply, flags);
}
}
- 客户端
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
/**
*/
// 参数1文件名,可为null,参数2文件长度
mMemoryFile = new MemoryFile(null, 1024);
//在设置了allowPurging为false之后,这个MemoryFile对应的Ashmem就会被标记成"pin",
// 那么即使在android系统内存不足的时候,也不会对这段内存进行回收
mMemoryFile.allowPurging(false);
android.os.Parcel data = android.os.Parcel.obtain();
android.os.Parcel reply = android.os.Parcel.obtain();
byte[] buffer = “31283216382163812362183621832163812”.getBytes();
mMemoryFile.writeBytes(buffer, 0, 0, buffer.length);
Method getFileDescriptorMethod = mMemoryFile.getClass().getDeclaredMethod(“getFileDescriptor”);
if (getFileDescriptorMethod != null) {
FileDescriptor fileDescriptor = (FileDescriptor) getFileDescriptorMethod.invoke(mMemoryFile);
// 序列化,才可传送
<