Bluetoothペアリングの解除について

3,253 views
Skip to first unread message

comas

unread,
Jun 7, 2011, 9:19:02 AM6/7/11
to 日本Androidの会
はじめましてcomasと申します。

現在、Bluetoothを利用したアプリケーションを作成しているのですが
1度ペアリングを行った端末に対して、ペアリングを解除する方法が見つかりません。
(アプリ上で接続を試みた端末に対して、アプリ終了時に
getBondedDevicesの中に情報を残したくないのでアプリ上で解除したい)

ペアリング情報を削除するということは可能でしょうか。
(端末の設定画面ではペアリング解除という操作ができるので
不可能ではないと思うのですが…)

ご教授お願いいたします。
何卒よろしくお願いいたします。

河西 正秀

unread,
Jun 16, 2011, 9:53:35 PM6/16/11
to 日本Androidの会
はじめまして、河西です。
偶然Bluetoothのペアリングの解除について調査していたところ、
こちらのメッセージに行き着きました。
大分時間がたってしまっているので、すでに解決されているかもしれませんが
AIDLで非公開インターフェイスにアクセスする方法で実現できましたので
残しておきたいと思います。

1. 以下のAIDLを作成する。

Eclipseのプロジェクトに以下のソースを作成します。(自動的に gen にIBluetooth

android.bluetooth.IBluetooth.aidl
http://code.google.com/p/backport-android-bluetooth/source/browse/trunk/backport-android-bluetooth201/eclair/IBluetooth.aidl?r=47

android.bluetooth.IBluetoothCallback.aidl
http://code.google.com/p/backport-android-bluetooth/source/browse/trunk/backport-android-bluetooth201/eclair/IBluetoothCallback.aidl?r=47

2. リフレクションを使って リモートオブジェクトのインターフェイスを取得する。

Class<?> serviceManagerClass =
Class.forName("android.os.ServiceManager");
Method method =
serviceManagerClass.getDeclaredMethod("getService", String.class);
IBinder ibinder = (IBinder) method.invoke(null, "bluetooth");

Class<?> ibluetoothClass =
Class.forName("android.bluetooth.IBluetooth");
Class<?> c = ibluetoothClass.getDeclaredClasses()[0];
Method asInterface = c.getDeclaredMethod("asInterface",
IBinder.class);
asInterface.setAccessible(true);
IBluetooth ibt = (IBluetooth) asInterface.invoke(null, ibinder);

3. デバイスのアンペアを行う。

ibt.removeBond(device.getAddress());

誰かのお役に立てれば幸いです。
以上です。
Reply all
Reply to author
Forward
0 new messages