安卓prevent蓝牙配对对话 [英] Android Prevent Bluetooth Pairing Dialog
问题描述
我开发一个内部应用程序,它使用蓝牙进行打印。我希望发生的蓝牙配对而无需用户输入。我曾设法让该工作通过捕获 android.bluetooth.device.action.PAIRING_REQUEST
播出。
I'm developing an internal application which uses Bluetooth for printing. I want the Bluetooth pairing to occur without user input. I have managed to get that working by trapping the android.bluetooth.device.action.PAIRING_REQUEST
broadcast.
在我的广播接收我称之为setPin法,配对工程确定,但 BluetoothPairingDialog
显示了一两秒钟,然后消失 - 见下面的链接。
In my broadcast receiver I call the setPin method, and pairing works ok, but a BluetoothPairingDialog
is displayed for a second or two, then it disappears - see link below.
<一个href="https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/bluetooth/BluetoothPairingDialog.java" rel="nofollow">https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
由于广播是无序的,我不能叫 abortBroadcast()
,并想知道是否有任何其他方式prevent配对对话框出现。我可以挂接到窗口管理器以某种方式?
Since the broadcast is non-ordered, I can't call abortBroadcast()
, and was wondering if there was any other way to prevent the pairing dialog from appearing. Can I hook into the window manager in some way?
推荐答案
老实说,我一直没能想出一个办法做到这一点,而无需修改SDK。如果您是OEM,很容易(我在4.3):
I honestly haven't been able to come up with a way to do this without modifying the sdk. If you're the OEM, it's easy (I'm on 4.3):
在封装/应用程序/设置/ AndroidManifest.xml中,发表意见的意图过滤器的配对对话框:
In packages/apps/Settings/AndroidManifest.xml, comment the intent filter for the pairing dialog:
<activity android:name=".bluetooth.BluetoothPairingDialog"
android:label="@string/bluetooth_pairing_request"
android:excludeFromRecents="true"
android:theme="@*android:style/Theme.Holo.Dialog.Alert">
<!-- <intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter> -->
</activity>
在框架/基/核心/爪哇/安卓/蓝牙/ BluetoothDevice.java删除从@hide的javadoc注释本恒
In frameworks/base/core/java/android/bluetooth/BluetoothDevice.java remove the @hide javadoc annotation from this constant
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_PAIRING_REQUEST =
"android.bluetooth.device.action.PAIRING_REQUEST";
和这个方法
public boolean setPairingConfirmation(boolean confirm)
然后注册自己的活动或广播接收机的BluetoothDevice.PAIRING_REQUEST行动。该广播接收器可以配对继续没有用户输入(仅当无引脚是必需的):
Then register your own activity or broadcast receiver for the BluetoothDevice.PAIRING_REQUEST action. This broadcast receiver allows pairing to continue without user input (only if no pin is required):
@Override
public void onReceive(Context context, Intent intent) {
if( intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST) ) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
device.setPairingConfirmation( true );
}
}
您将需要重建的SDK和编译code对新版本,以获得进入常数和方法,并取代Settings.apk对/系统分区关闭对话框。您可能也可能需要运行作为一个系统应用程序,但我觉得可能不是。
You'll need to rebuild the sdk and compile your code against the new version to get access to the constant and methods, and replace Settings.apk on the /system partition to disable the dialog. You may possibly also need to be running as a system app but I think likely not.
这篇关于安卓prevent蓝牙配对对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!