Android7.0 realease版本中已经将framework/opt/bluetooth中的pbap部分移植package/apps/Bluetooth的蓝牙应用中,所以之前用到framework/opt/bluetooth中pbap部分的代码已经无法正常使用了。但研读代码过程中发现蓝牙应用中已经提供了从蓝牙导入联系人、通话记录的服务。
这里给出调用该服务的简单方法。
一、连接服务
private IBluetoothPbapClient mBluetoothPbapClient = null;
private final ServiceConnection mPbapServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mBluetoothPbapClient = IBluetoothPbapClient.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Logger.v(TAG, "onServiceDisconnected()");
}
};
ComponentName component = new ComponentName("com.android.bluetooth", "com.android.bluetooth.pbapclient.PbapClientService");
Intent intent = new Intent();
intent.setComponent(component);
boolean serviceResult = bindService(intent, mPbapServiceConnection, BIND_AUTO_CREATE);
二、获得蓝牙设备后的导入操作
private void importContactsWithBluetooth(BluetoothDevice device ){
mBluetoothPbapClient.setPriority(device , );
mBluetoothPbapClient.connect(device);
}
想深入了解开发可以去研读packages/apps/Bluetooth/src/com/android/bluetooth/pbapclient$部分的代码。