BluetoothでのBroadcastReceiverについて

713 views
Skip to first unread message

はち@Yuichi_Otsubo

unread,
Sep 15, 2010, 10:45:12 PM9/15/10
to 日本Androidの会
お世話になっております。

Bluetoothで他のデバイスを検索したいのですが、
BroadcastReceiver内のonReceiveイベントを発生することが
できません。
getBondedDevices()では、デバイスを取得できています。

設定方法等、ご存知の方、
ご教授頂けませんでしょうか。

端末:XPERIA

BluetoothReceiver mBluetoothReceiver = new BluetoothReceiver();
registerReceiver( mBluetoothReceiver, new IntentFilter(
BluetoothDevice.ACTION_FOUND));
mBluetoothAdapter.startDiscovery();
上記で、検索スタート。

class BluetoothReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
}
}
}

Satoshi Sakamoto

unread,
Sep 15, 2010, 11:42:35 PM9/15/10
to android-g...@googlegroups.com
はじめまして、坂本と申します。

Xperiaですと、backport.android.bluetoothパッケージを使っておられるのだと思いますが、
まずは、API Level 5 以上用のサンプル・アプリ・ソースのBluetoothChatに含まれる
DeviceListActivityだけを動作させてみてはいかがでしょうか。


IS01では、
backport.android.bluetoothパッケージを使っても、
Bluetooth-SPPに非対応なのでBluetoothChat自体は動きませんが、
DeviceListActivityだけなら動きました。


2010年9月16日11:45 はち@Yuichi_Otsubo <our.dream....@gmail.com>:

> --
> このメールは Google グループのグループ「日本Androidの会」の登録者に送られています。
> このグループに投稿するには、android-g...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-group-j...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-group-japan?hl=ja からこのグループにアクセスしてください。
>
>

はち@Yuichi_Otsubo

unread,
Sep 16, 2010, 12:10:56 AM9/16/10
to 日本Androidの会
坂本様

お返事ありがとうございます。

実はご指摘のサンプルで、DeviceListActivity中の
btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
if (pairedDevices.size() > 0)
{
for (BluetoothDevice device:pairedDevices)
{
devices.add(device.getName()
+System.getProperty("line.separator")+
device.getAddress()
);
}
}
は、動作しています。

btAdapter.startDiscovery();を発行し、
onReceiveが来ていません。

AndroidManifest.xmlかどこかに何か設定は必要でしょうか。

On 9月16日, 午後12:42, Satoshi Sakamoto <s.moto.s...@gmail.com> wrote:
> はじめまして、坂本と申します。
>
> Xperiaですと、backport.android.bluetoothパッケージを使っておられるのだと思いますが、
> まずは、API Level 5 以上用のサンプル・アプリ・ソースのBluetoothChatに含まれる
> DeviceListActivityだけを動作させてみてはいかがでしょうか。
>
> ※
> IS01では、
> backport.android.bluetoothパッケージを使っても、
> Bluetooth-SPPに非対応なのでBluetoothChat自体は動きませんが、
> DeviceListActivityだけなら動きました。
>
> 2010年9月16日11:45 はち@Yuichi_Otsubo <our.dream.comes.t...@gmail.com>:

Satoshi Sakamoto

unread,
Sep 16, 2010, 12:30:59 AM9/16/10
to android-g...@googlegroups.com
はち様

なるほど。そうでしたか。

AndroidManifest.xmlには
DeviceListActivityの他に
backport-android-bluetooth系のactivityを書いておく必要があります。
※あとbackport_android_bluetooth.propertiesもプロジェクト・フォルダのres内に置いておく必要がありますね。

backport-android-bluetoothの本家のesmasuiさんのサイトをご覧ください。
http://code.google.com/p/backport-android-bluetooth/


2010年9月16日13:10 はち@Yuichi_Otsubo <our.dream....@gmail.com>:

はち@Yuichi_Otsubo

unread,
Sep 16, 2010, 1:21:46 AM9/16/10
to 日本Androidの会
坂本様

ご回答ありがとうございます。
下記内容で、無事取得できました。

助かりました。
ありがとうございました。

失礼致します。

On 9月16日, 午後1:30, Satoshi Sakamoto <s.moto.s...@gmail.com> wrote:
> はち様
>
> なるほど。そうでしたか。
>
> AndroidManifest.xmlには
> DeviceListActivityの他に
> backport-android-bluetooth系のactivityを書いておく必要があります。
> ※あとbackport_android_bluetooth.propertiesもプロジェクト・フォルダのres内に置いておく必要がありますね。
>
> backport-android-bluetoothの本家のesmasuiさんのサイトをご覧ください。
> ■http://code.google.com/p/backport-android-bluetooth/
>
> 2010年9月16日13:10 はち@Yuichi_Otsubo <our.dream.comes.t...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages