Bluetooth don't search for new devices/ how to send String message via Bluetooth?

I am using bluetooth in my app, i want my app ti search for new devices and make pair with them and then send a predefined message to them, this is what i did so far :

1- this is the function that initialize my Bluetooth variables

public void BlutoothInit()

{

BlutoothListView=(ListView)findViewById(R.id.minimal_profile);

pairedDevices = new ArrayList<String>();
    filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    receiver = new 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);
                devices.add(device);
                String s = "";
                for(int a = 0; a < pairedDevices.size(); a++){
                    if(device.getName().equals(pairedDevices.get(a))){
                        s = "(Paired)";
                        break;
                    }
                }

                listAdapter.add(device.getName()+" "+s+" "+"\n"+device.getAddress());
            }

            else if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
            }
            else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){         
            }
            else if(BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
                if(btAdapter.getState() == btAdapter.STATE_OFF){
                    //turnOnBT();
                }
            }

        }
    };
        registerReceiver(receiver, filter);
         filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
        registerReceiver(receiver, filter);
         filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
        registerReceiver(receiver, filter);
         filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        registerReceiver(receiver, filter);
}

2- her i am using Bluetooth

public void via_bluetooth (View v) {
getPairedDevices();


final ListView DevicesListView = (ListView) findViewById(R.id.minimal_profile);

ArrayAdapter<String> adapter;

adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,DevicesList);

DevicesListView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    DevicesListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
                Toast.makeText(getApplicationContext(), "device is not paired", 0).show();
            return true;
        }                 
      });

}

the function "getPairedDevices" works fine and i get all the devices that i made pair with from outside my app but when i call this function to scan new devices

public void ScanNewDevices(View v) {
    // TODO Auto-generated method stub
    if (btAdapter.isDiscovering()) {
        btAdapter.cancelDiscovery();
    }   
    btAdapter.startDiscovery();
    try{
    final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            // When discovery finds a device
            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
                DevicesList.add(device.getName() + "\n" + device.getAddress());
            }
        }
    };
    // Register the BroadcastReceiver
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
    }
     catch (Exception e) {
            Toast.makeText(getApplicationContext(), e.toString(), 0).show();
         }
}

an error says "Source not found." appears and do nothing !!! whats iam doing wrong and what is missing to search for devices and send them a message ?

Answers


 private void pairDevice(BluetoothDevice device) {
    try {

        Method m = device.getClass().getMethod("createBond", (Class[]) null);
        m.invoke(device, (Object[]) null);

        Toast.makeText(context,"paired finished",3000).show();
        } catch (Exception e) 
          {
        Toast.makeText(context,"error"+e.getMessage(),3000).show();

    }
    }
      //try this for paring...

Need Your Help

wmi and network drives

c# permissions wmi wmi-service

I have an application which uses WMI to do stuff on a remote machine.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.