[SOLUTION]
修改\frameworks\base\core\java\android\bluetooth\BluetoothDevice.java文件createBond(),
//added MTK, Replace the headset name here.
+++ public static final String BLACK_LIST_BOND_MOTO_S305 = "moto s305";
public boolean createBond() {
if (sService == null) {
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
return false;
}
+++ //added MTK
+++ if(BLACK_LIST_BOND_MOTO_S305.equals(getAliasName())){
+++ if (DBG) Log.d(TAG, "Do not bond Mota S305 headset.");
+++ return false;
+++ }
+++ // added end
try {
if (DBG) Log.d(TAG, "createBond: " + this);
return sService.createBond(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
如此修改会弹出配对失败提示,
提示来自于\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothDevicePreference.java中,
private void pair() {
if (!mCachedDevice.startPairing()) {
Utils.showError(getContext(), mCachedDevice.getName(),
R.string.bluetooth_pairing_error_message);
}
}
如需修改弹框提示,可以在这里添加,也可不修改此处!
//added MTK, Replace the headset name here.
+++ public static final String BLACK_LIST_BOND_MOTO_S305 = "moto s305";
private void pair() {
if (!mCachedDevice.startPairing()) {
+++ //added MTK
+++ if(BLACK_LIST_BOND_MOTO_S305.equals(mCachedDevice.getName())){
+++ Utils.showError(getContext(), mCachedDevice.getName(),
+++ "Can not bond Mota S305");
+++ }else {
Utils.showError(getContext(), mCachedDevice.getName(),
R.string.bluetooth_pairing_error_message);
+++ }
+++ //added end
}
}
转载于:https://blog.51cto.com/132588761/1965627