I'm trying to scan and discover bluetooth devices and put in in a
clickable ListView. When i use 'extend Activity' without any
ListActivity implementation it works fine. But when I start using any
ListActivity implementation, everything doesnt work. The ListActivity
wouldn't even run. Here is the code (assuming bluetooth is already
running).
-------------------------------------------------------
package com.project;

import java.util.ArrayList;

import android.app.ListActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;


public class DetectBluetoothDevices extends ListActivity {

        private static final String LOG_TAG = "selina";

        ListView listDevicesFound;
        BluetoothAdapter bluetoothAdapter;
        ArrayAdapter<String> btArrayAdapter;
        ArrayList<String> al;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.bt_devices_list);


                bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                al = new ArrayList<String>();

        al.clear();
        bluetoothAdapter.startDiscovery();

        registerReceiver(mReceiver, new
IntentFilter(BluetoothDevice.ACTION_FOUND));

                setListAdapter(new ArrayAdapter<String>(this,
R.layout.bt_devices_list, al));
                listDevicesFound = (ListView)findViewById(R.id.devicesfound);
                listDevicesFound.setTextFilterEnabled(true);

                listDevicesFound.setOnItemClickListener(new 
OnItemClickListener()
                {
                        public void onItemClick (AdapterView<?> parent, View 
view,
                                        int position, long id){
                                Toast.makeText(getApplicationContext(), 
((TextView)
view).getText(),
                                                Toast.LENGTH_SHORT).show();
                        }
                });
        }

        private final BroadcastReceiver mReceiver = 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);
                        al.add(device.getName() + "~" + device.getAddress());
                        Log.v(LOG_TAG, "device name+address: " + 
device.getName() + " ~
" + device.getAddress());
                        Log.v(LOG_TAG, "arrayList: " + al);
                }
        }
    };
}

---------------------------------------------------------------------
In the LogCat - error says Fatal Exception: Main....... Failed Binder
Transaction

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to