Android蓝牙配对对话框显示少于1秒
创始人
2024-10-08 21:31:54
0
  1. 可以自定义蓝牙配对对话框,以便控制对话框的显示时间。可参考以下示例代码:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device.getBondState() == BluetoothDevice.BOND_BONDING) {
   //  自定义配对对话框
   final Dialog dialog = new Dialog(context);
   dialog.setContentView(R.layout.custom_bluetooth_pairing_dialog);
   dialog.setTitle(R.string.bluetooth_pairing_title);

   ((TextView) dialog.findViewById(R.id.tvDescription)).setText(context.getString(R.string.bluetooth_pairing_text, device.getName()));
   Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
   btnCancel.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
           dialog.dismiss();
       }
   });
   dialog.show();

   //  设置5秒钟后自动隐藏对话框
   new Handler().postDelayed(new Runnable() {
       @Override
       public void run() {
           if (dialog.isShowing()) {
               dialog.dismiss();
           }
       }
   }, 5000);
}
  1. 如果不需要自定义对话框,可以通过反射来改变配对对话框的显示时间。可参考以下示例代码:
private void setPairingConfirmation(BluetoothDevice device, boolean confirm) throws Exception {
    Method setPairingConfirmationMethod = device.getClass().getDeclaredMethod("setPairingConfirmation", boolean.class);
    setPairingConfirmationMethod.invoke(device, confirm);
    if (!confirm) {
        Method cancelPairingUserInputMethod = device.getClass().getDeclaredMethod("cancelPairingUserInput");
        cancelPairingUserInputMethod.invoke(device);
    }
}

private void pairDevice(BluetoothDevice device) {
    if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
        try {
            setPairingConfirmation(device, true);
            device.createBond();
            //  反射设置配对对话框显示时间为10秒
            int timeout = 10000;
            Field field = device.getClass().getField("TRANSACTION_PAIRING_WAIT");
            int TRANSACTION

相关内容

热门资讯

透视app!红龙poker辅助... 透视app!红龙poker辅助平台(透视)竟然是真的有挂(详细辅助第三方教程);亲,关键说明,红龙p...
最新通报!wepoker辅助器... 最新通报!wepoker辅助器安装包,wepoker透视脚本安卓,攻略教程(有挂透明);支持2-10...
透视工具!hhpoker透视脚... 透视工具!hhpoker透视脚本(透视)切实是有挂(详细辅助揭秘教程)1、实时hhpoker透视脚本...
透视私人局!wepoker辅助... 透视私人局!wepoker辅助插件功能(透视)其实是真的有挂(详细辅助规律教程);一、AI软件牌型概...
分享一款!wpk作弊,hhpo... 分享一款!wpk作弊,hhpoker作弊码怎么用,实用技巧(有挂神器);玩家必备必赢加哟《13670...
透视科技!hhpoker脚本下... 透视科技!hhpoker脚本下载(透视)竟然真的是有挂(详细辅助靠谱教程)1、玩家可以在软件透明挂俱...
玩家必知教程!拱趴大菠萝有什么... 1、玩家必知教程!拱趴大菠萝有什么挂,hhpoker有没有作弊辅助,攻略方法(有挂方法)。2、hhp...
透视辅助!wepoker透视辅... 透视辅助!wepoker透视辅助下载(透视)竟然是真的有挂(详细辅助介绍教程);1、wepoker透...
必备攻略!wepoker透视最... 必备攻略!wepoker透视最简单三个步骤,wepoker可以开透视吗,AI教程(有挂透明);wep...
一分钟揭秘!wepoker是不... 一分钟揭秘!wepoker是不是有人用挂,wepoker破解器激活码,细节揭秘(有挂软件)1、玩家可...