温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何添加某设备至配对黑名单?

发布时间:2020-07-02 18:05:23 来源:网络 阅读:685 作者:12你好好吗 栏目:移动开发

[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
}

}

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI