简体   繁体   English

删除蓝牙配对请求提示

[英]Remove Bluetooth Pairing Request Prompt

So my device is a silent device. 所以我的设备是静音设备。 What I want is that when I send a pairing request to khadas from a different device, device automatically pairs. 我想要的是,当我从其他设备向khadas发送配对请求时,设备会自动配对。 The problem is when a bluetooth pairing request is sent, a pairing confirmation prompt with pin comes up. 问题是,当发送蓝牙配对请求时,会出现带有PIN的配对确认提示。 I have setup a Broadcast Receiver from here , but nothing seems to work the code is : 从这里设置了一个广播接收器,但是似乎没有任何作用,代码是:

private final BroadcastReceiver mPairingRequestReceiver = new BroadcastReceiver()
    {
        public void onReceive(Context context, Intent intent)
        {
            Log.v("BDE", "recieved something!");
            String action = intent.getAction();
            if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST))
            {
                try
                {
                    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    int pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234);
                    //the pin in case you need to accept for an specific pin
                    Log.d(TAG, "Start Auto Pairing. PIN = " + intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234));
                    byte[] pinBytes;
                    pinBytes = ("" + pin).getBytes("UTF-8");
                    device.setPin(pinBytes);
                    //setPairing confirmation if needed
                    device.setPairingConfirmation(true);
                } catch (Exception e)
                {
                    e.printStackTrace();
                    Log.e(TAG, "Error occurs when trying to auto pair");
                    e.printStackTrace();
                }
            }
        }
    };

When I run this code, I get a error "Caused by: java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10068 nor current process has android.permission.BLUETOOTH_PRIVILEGED." 运行此代码时,出现错误“由:java.lang.SecurityException引起:需要BLUETOOTH PRIVILEGED权限:用户10068或当前进程都没有android.permission.BLUETOOTH_PRIVILEGED。”

I have added the permission in Android Manifest too and have installed the app as system app too, still it does not work. 我也在Android Manifest中添加了该权限,并且也已将该应用程序安装为系统应用程序,但仍然无法正常工作。

Found the Solution, if you have root access and you are installing the app as system app to get the bluetooth_privileged permission. 如果您具有超级用户访问权限,并且要将该应用程序安装为系统应用程序以获取bluetooth_privileged权限,请找到解决方案。 Copy the apk into /system/priv-app instead of /system/app 将apk复制到/ system / priv-app而不是/ system / app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM