AndroidシールドBluetooth接続時の初のペアリングシステム弾窓
2620 ワード
ペアリングパスワードが既知で固定するBluetoothデバイスを接続すると、コード内でペアリングが完了するのに、システムからペアリングウィンドウがポップアップする.
これは間違いなくつらい.
そこで、このペアリングウィンドウを遮断しようとした.
要点:システムからのBluetoothペアリングブロードキャスト を中断するは、ClsUtilsオープンソースフレーム を使用する必要がある.個人テストはAndroid 4.4でブロックに成功し、4.2ではだめです.高バージョンでBluetoothペアリング放送を秩序正しく放送するためかもしれません.
code:
予め設定するパスワードにより直接サイレントペアを作成する.
manifest:
受信機の優先度は最高1000とする、最初に放送通知されることを保証する.
これは間違いなくつらい.
そこで、このペアリングウィンドウを遮断しようとした.
要点:
code:
public class BluetoothConnectReceiver extends BroadcastReceiver { private final String TAG = "BluetoothConnectReceiver"; @SuppressLint("NewApi") @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, TAG + " -> BluetoothConnectReceiver start!"); if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) { BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Log.i(TAG, TAG + " -> ddd"); try { Log.i(TAG, TAG + " -> Device Name = " + btDevice.getName()); if ("Device Name X".equals(btDevice.getName())) { abortBroadcast(); ClsUtils.setPin(btDevice.getClass(), btDevice, "password"); ClsUtils.createBond(btDevice.getClass(), btDevice); ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice); } } catch (Exception e) { e.printStackTrace(); } } } }
予め設定するパスワードにより直接サイレントペアを作成する.
manifest:
<receiver android:name=".BluetoothConnectReceiver" >
<intent-filter android:priority="1000" >
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>
受信機の優先度は最高1000とする、最初に放送通知されることを保証する.