Android Prevent Bluetooth Pairing Dialog -
i'm developing internal application uses bluetooth printing. want bluetooth pairing occur without user input. have managed working trapping android.bluetooth.device.action.pairing_request
broadcast.
in broadcast receiver call setpin method, , pairing works ok, bluetoothpairingdialog
displayed second or two, disappears - see link below.
since broadcast non-ordered, can't call abortbroadcast()
, , wondering if there other way prevent pairing dialog appearing. can hook window manager in way?
i haven't been able come way without modifying sdk. if you're oem, it's easy (i'm on 4.3):
in packages/apps/settings/androidmanifest.xml, comment intent filter 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>
in frameworks/base/core/java/android/bluetooth/bluetoothdevice.java remove @hide javadoc annotation constant
@sdkconstant(sdkconstanttype.broadcast_intent_action) public static final string action_pairing_request = "android.bluetooth.device.action.pairing_request";
and method
public boolean setpairingconfirmation(boolean confirm)
then register own activity or broadcast receiver bluetoothdevice.pairing_request action. broadcast receiver allows pairing continue without user input (only if no pin 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 ); } }
you'll need rebuild sdk , compile code against new version access constant , methods, , replace settings.apk on /system partition disable dialog. may possibly need running system app think not.
Comments
Post a Comment