如何添加某設備至配對黑名單?

[SOLUTION]

html

修改\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);
}
java

}
如需修改彈框提示,能夠在這裏添加,也可不修改此處!
//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
}
android

}
app

相關文章
相關標籤/搜索