hi all, i want to display the list of bounded devices with the android 
bluetooth api , but i don't know why in this code when i run it in my 
device no toast is displayed by the way toast will conatain name of each 
device  .who  can help me ? and thx in advance :) 
this is the code 

package com.example.fatma.cst;
import android.bluetooth.BluetoothAdapter;import 
android.bluetooth.BluetoothDevice;import android.content.Intent;import 
android.os.Bundle;import android.support.v7.app.AppCompatActivity;import 
android.widget.TextView;import android.widget.Toast;
import java.util.Set;import java.util.Vector;
public class MainActivity extends AppCompatActivity {
    TextView txt = null;
    private static final int REQUEST_ENABLE_BT = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        final Vector mArrayAdapter = null;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BluetoothAdapter bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();

        if(bluetoothAdapter==null){
            Toast t=new Toast(this);
            t.setText("Sorry your phone do not support Bluetooth");
            t.show();
        }
        else
        {
            if (!bluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new 
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            }

            if(REQUEST_ENABLE_BT!=0) {



    /* bluetoothAdapter.startDiscovery();
                BroadcastReceiver mReceiver = new BroadcastReceiver() {
                    public void onReceive(Context context, Intent intent) {
                        String action = intent.getAction();

                        //Finding devices
                        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                            // Get the BluetoothDevice object from the Intent
                            BluetoothDevice device = 
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                            // Add the name and address to an array adapter to 
show in a ListView
                            mArrayAdapter.add(device.getName() + "\n" + 
device.getAddress());



                        }
                    }

                };*/

                //IntentFilter filter = new 
IntentFilter(BluetoothDevice.ACTION_FOUND);
               // registerReceiver(mReceiver, filter);
               Set<BluetoothDevice> devices;

                devices = bluetoothAdapter.getBondedDevices();
                for (BluetoothDevice blueDevice : devices) {
                    Toast.makeText(this, "Device = " + blueDevice.getName(), 
Toast.LENGTH_SHORT).show();
                }
            }
        }


    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/323e3772-1a94-49f4-9357-a4e3afbde332%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to