title: How to calculate distance between two android device using Bluetooth signal strength?
body: <p>I'm working on android application. In my project I want to show Bluetooth scanning device, MAC Address, Bluetooth signal strength and Distance between two Android device.</p>
  
  <p>I have done 3 requirements but I don't know how to get distance using Signal strength.</p>
  
  <pre><code>package com.example.bluetoothdemo;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Set;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.net.wifi.WifiInfo;
  import android.net.wifi.WifiManager;
  import android.os.Bundle;
  import android.app.Activity;
  import android.bluetooth.BluetoothAdapter;
  import android.bluetooth.BluetoothDevice;
  import android.content.Intent;
  import android.view.Menu;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.content.BroadcastReceiver;
  
  public class MainActivity extends Activity {
   private BluetoothAdapter BTAdapter = BluetoothAdapter.getDefaultAdapter();
  private static final int REQUEST_ENABLE_BT = 1;
  
  ListView listDevicesFound;
  Button btnScanDevice;
  TextView stateBluetooth;
  BluetoothAdapter bluetoothAdapter;
  
  ArrayAdapter&lt;String&gt; btArrayAdapter;
  
  /**  Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  
    btnScanDevice = (Button)findViewById(R.id.scan_device);
  
    stateBluetooth = (TextView)findViewById(R.id.textView1);
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  
    listDevicesFound = (ListView)findViewById(R.id.listView1);
  
    btArrayAdapter = new ArrayAdapter&lt;String&gt;(MainActivity.this, 
  
     android.R.layout.simple_list_item_1);
    listDevicesFound.setAdapter(btArrayAdapter);
  
    CheckBlueToothState();
  
    btnScanDevice.setOnClickListener(btnScanDeviceOnClickListener);
  
    registerReceiver(ActionFoundReceiver,   new IntentFilter(BluetoothDevice.ACTION_FOUND));
    registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
     }
  
  
          @Override
  
       protected void onDestroy() {
  // TODO Auto-generated method stub
    super.onDestroy();
  unregisterReceiver(ActionFoundReceiver);
   }
  
        private void CheckBlueToothState(){
     if (bluetoothAdapter == null){
     stateBluetooth.setText("Bluetooth NOT support");
      }else{
     if (bluetoothAdapter.isEnabled()){
      if(bluetoothAdapter.isDiscovering()){
       stateBluetooth.setText("Bluetooth is currently in device discovery process.");
      }else{
       stateBluetooth.setText("Bluetooth is Enabled.");
       btnScanDevice.setEnabled(true);
      }
     }else{
      stateBluetooth.setText("Bluetooth is NOT Enabled!");
      Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
         startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
     }
    }
   }
  
     private Button.OnClickListener btnScanDeviceOnClickListener  = new Button.OnClickListener(){
  
  
        @Override
      public void onClick(View arg0) {
       // TODO Auto-generated method stub
    btArrayAdapter.clear();
    bluetoothAdapter.startDiscovery();
          }};
  
         @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          if(requestCode == REQUEST_ENABLE_BT){
        CheckBlueToothState();
       }
  }
  
      private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver(){
  
       @Override
          public void onReceive(Context context, Intent intent) {
       // TODO Auto-generated method stub
        String action = intent.getAction();
      if(BluetoothDevice.ACTION_FOUND.equals(action)) {
         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
         btArrayAdapter.add(device.getName() + "\n" + device.getAddress()+ "        
   \n "+intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE));
         btArrayAdapter.notifyDataSetChanged();
     }
    }};
       @Override
     public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
  }
  
     private final BroadcastReceiver receiver = new BroadcastReceiver(){
     @Override
     public void onReceive(Context context, Intent intent) {
  
      String action = intent.getAction();
      if(BluetoothDevice.ACTION_FOUND.equals(action)) {
          int  rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
          String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
          TextView rssi_msg = (TextView) findViewById(R.id.listView1);
  
          Toast.makeText(getApplicationContext(),"  RSSI: " + rssi + "dBm",     
     Toast.LENGTH_SHORT).show();
      }
   }
    };
   }
  </code></pre>