2016-06-29 7 views
1

接続したBluetoothデバイスの名前を取得する方法アンドロイドのBluetoothデバイスが接続されている場合は、ここでは、私がここにアンドロイド で接続したBluetoothデバイスの名前を取得する方法を知りたい

NetworkInfo bluetooth = connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH); 
if(bluetooth.isConnected()) 
       { 
        Toast.makeText(myprofile3Context,"bluetooth is connected", Toast.LENGTH_SHORT).show(); 
       } 

は、私がチェックしたコードですかない。ブルートゥースが接続されている場合、私は接続されているデバイスの名前を取得する方法を知りたい。

+0

permissionsを追加https://cmanios.wordpress.com/2012/05/09/bluetooth-adapter- device-name-and-mac-address-in-android/ –

答えて

0

この

 
     public String getLocalBluetoothName(){ 
     if(mBluetoothAdapter == null){ 
      mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
     } 
     String name = mBluetoothAdapter.getName(); 
     if(name == null){ 
      System.out.println("Name is null!"); 
      name = mBluetoothAdapter.getAddress(); 
     } 
     return name; 
    } 

+1

自分のデバイス名を取得できません。私は他の接続されたデバイス名を取得したい –

0
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 

     // When discovery finds a device 
     if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { 
      // Get the BluetoothDevice object from the Intent 
      BluetoothDevice device = intent 
        .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 

          //you can get name by device.getName() 

     } else if (BluetoothAdapter.ACL_DISCONNECTED 
       .equals(action)) { 

     } 
    } 
}; 

使用extendsBroadcastReceiverを試してみて、これはあなたを助けるmanifest

+0

私はブロードキャスト受信者なしでそれをしたい –

関連する問題