2012-01-09 16 views
1

AndroidでBluetoothを使用する方法を学習しています。私は Android Bluetoothはサポートされていません

マニフェストファイルに
<uses-permission android:name="android.permission.BLUETOOTH" /> 
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> 

をこの権限を与えているとメインのコードはここにある:

private static final int REQUEST_ENABLE_BT = 0; 
private static final int REQUEST_DISCOVERABLE_BT = 0; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    final TextView out=(TextView)findViewById(R.id.out); 
    final Button button = (Button) findViewById(R.id.button1); 
    final Button button1 = (Button) findViewById(R.id.button2); 
    final Button button2 = (Button) findViewById(R.id.button3); 
    final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
    if (mBluetoothAdapter == null) { 
     out.append("device not supported"); 
    } 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      if (!mBluetoothAdapter.isEnabled()) { 
       Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
       startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 
      } 
     } 
    }); 
    button1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      if (!mBluetoothAdapter.isDiscovering()) { 
        Context context = getApplicationContext(); 
        CharSequence text = "MAKING YOUR DEVICE DISCOVERABLE"; 
        int duration = Toast.LENGTH_SHORT; 
        Toast toast = Toast.makeText(context, text, duration); 
        toast.show(); 
       Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); 
       startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT); 
      } 
     }    
    }); 
    button2.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) {  
      mBluetoothAdapter.disable(); 
      Context context = getApplicationContext(); 
       CharSequence text = "TURNING_OFF BLUETOOTH"; 
       int duration = Toast.LENGTH_SHORT; 
       Toast toast = Toast.makeText(context, text, duration); 
       toast.show(); 
      } 
    }); 
} 

しかし、それは私に言っている:

デバイスが

をサポートしていません画面上にあり、ボタンをクリックするとアプリケーションが強制的に閉じるので、私のandrの問題は何ですか? oidエミュレータ?

答えて

1

エミュレータのBluetoothをサポートしていませんが、実際のデバイスを使用

+0

Iは、上のサンプルコードをテストしていエミュレータと私はアンドロイドの電話を持っていないので、それを修正する方法はありますか? –

+0

申し訳ありませんが、おそらく修正するための良い考えがありません。 – idiottiger

+0

エミュレータでプロジェクトを作成しましたか? –

1

device not supportedは、AndroidエミュレータがBluetoohをサポートしていないためであるとき

if (mBluetoothAdapter == null) { 
     out.append("device not supported"); 
    } 

あなたが得るメッセージです。 Bluetooth対応のアプリケーションを確認するには、物理​​的なデバイスが必要です。

アプリケーションでBluetoothを使用する前にエミュレータのいくつかの制限についてthisを読むために必要な追加情報

How to use Bluetooth in Android emulator?
Bluetooth support on Android Emulator

3

ためにこれらの質問を確認してください。

0

ブルートゥースがサポートされていない場合は、エミュレータにqemu -btオプションが付いているのはなぜですか?ブルートゥース上のUSBキーボードのエミュレーションはなぜですか?サポートされているようにBluetoothを有効にする必要があります。 BOARD_HAVE_BLUETOOTHを追加する以外に必要な特定の設定や特定のターゲットがある可能性があります。= BoardConfig.mkにtrue?

ブルートゥースがエミュレータで有効になるようにBluetoothを設定するにはどうすればよいですか?

bt [:hci-type] '-bt hci'オプションと同じ形式で指定されたタイプのBluetoothドングルは、許可されたHCIタイプを参照してください。タイプが指定されない場合、HCIロジックは-bt hci、vlan = 0に対応します。このUSBデバイスは、HCIのUSBトランスポートレイヤを実装します。使用例:

QEMU [... OPTIONS ...] -usbdevice BT:HCI、VLAN = 3 -bt装置:キーボード、VLAN = 3

http://wiki.qemu.org/download/qemu-doc.html#usb_005fdevices

関連する問題