16

印刷に Bluetooth を使用する内部アプリケーションを開発しています。ユーザー入力なしで Bluetooth ペアリングを実行したい。android.bluetooth.device.action.PAIRING_REQUESTブロードキャストをトラップすることで、なんとか機能させることができました。

私のブロードキャスト レシーバーで setPin メソッドを呼び出すと、ペアリングは正常に機能しますが、aBluetoothPairingDialogが 1 ~ 2 秒間表示されてから消えます。以下のリンクを参照してください。

https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/bluetooth/BluetoothPairingDialog.java

ブロードキャストは順序付けされていないため、 に電話することはできずabortBroadcast()、ペアリング ダイアログが表示されないようにする方法が他にないかと考えていました。何らかの方法でウィンドウマネージャーに接続できますか?

4

1 に答える 1

3

正直なところ、SDK を変更せずにこれを行う方法を思いつくことができませんでした。あなたが OEM なら簡単です (私は 4.3 を使用しています)。

packages/apps/Settings/AndroidManifest.xml で、ペアリング ダイアログのインテント フィルターをコメント化します。

<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>

Frameworks/base/core/java/android/bluetooth/BluetoothDevice.java で、この定数から @hide javadoc アノテーションを削除します

@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 アクション用に独自のアクティビティまたはブロードキャスト レシーバーを登録します。このブロードキャスト レシーバーを使用すると、ユーザーの入力なしでペアリングを続行できます (ピンが必要ない場合のみ)。

@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 を再構築し、新しいバージョンに対してコードをコンパイルして定数とメソッドにアクセスし、/system パーティションの Settings.apk を置き換えてダイアログを無効にする必要があります。システムアプリとして実行する必要があるかもしれませんが、おそらくそうではないと思います。

于 2014-05-16T16:24:22.647 に答える