一、import com.rt.bluetooth.utity.TelContact;
interface IBluetoothServiceCallBacks {
void callback(String name);
void getPhoneBooks( inout List<TelContact> list);
void getDriviceName(String driviceName);
void getDrivicePin(String drivicePin);
void getContacts( inout List<TelContact> list);
void getBtStates(int state);
void getPhoneNum(String num);
void getMusicStates(boolean flag);
void getCount(int count);
void getPhoneBook(in TelContact telContact);
void getContact(in TelContact telContact);
void getPhoneBooksadd( inout List<TelContact> list,int flag);
}
二、public class TelContact implements Parcelable {
public static String TAG = "TelContact";
private String name;
private String num;
private String time;
private String type;
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public TelContact() {
super();
}
public TelContact(String name, String num, String time, String type) {
super();
this.name = name;
this.num = num;
this.time = time;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
// 测试用
// 以下为aidl传递对象需要的操作
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return "TelContact [name=" + name + ", num=" + num + ", time=" + time
+ ", type=" + type + "]";
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(name);
dest.writeString(num);
dest.writeString(time);
dest.writeString(type);
}
public static final Parcelable.Creator<TelContact> CREATOR = new Creator<TelContact>() {
@Override
public TelContact createFromParcel(Parcel source) {
String name = source.readString();
String num = source.readString();
String time = source.readString();
String type = source.readString();
TelContact telContact = new TelContact();
telContact.setName(name);
telContact.setNum(num);
telContact.setTime(time);
telContact.setType(type);
return telContact;
}
@Override
public TelContact[] newArray(int size) {
return new TelContact[size];
}
};
}
parcelable TelContact;
三、private RemoteCallbackList <IBluetoothServiceCallBacks> mCallbacks = new RemoteCallbackList <IBluetoothServiceCallBacks>();
四、@Override
public void registerCallback(IBluetoothServiceCallBacks callBack)
throws RemoteException {
// TODO Auto-generated method stub
RTLogUtils.i(TAG, "注册registerCallback1="+callBack);
if(callBack!=null){
RTLogUtils.i(TAG, "注册registerCallback2="+callBack);
mCallbacks.register(callBack);
BtApplication.callBacks = callBack;
RTLogUtils.i(TAG, "BtApplication.callBacks注册"+BtApplication.callBacks);
RTLogUtils.i(TAG, BtApplication.deviceName+";"+BtApplication.devicePin);
callBack.getDriviceName(BtApplication.deviceName);
callBack.getDrivicePin(BtApplication.devicePin);
}
}
五、interface IBluetoothService {
void registerCallback(IBluetoothServiceCallBacks callBack);
void unregisterCallback(IBluetoothServiceCallBacks callBack);
}
关于AIDL与回调的一些记录
最新推荐文章于 2024-05-25 15:59:23 发布