fabiberlin / android-bluetooth

Automatically exported from code.google.com/p/android-bluetooth
0 stars 0 forks source link

DeviceAdapter not raising some events -- HTC Tatoo Can't find any devices #24

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Referenced AndroidBluetoothAPI_0.3.jar in build paths as external
2.Checked if localBluetoothDevice.isEnabled()
3.Called localBluetoothDevice.scan();

What is the expected output? What do you see instead?
scanCompleted should return non-zero value; I have a moto headset that
works with the phone turned on next to it.
Only scanCompleted is called; scanStarted() is never called;

What version of the product are you using? On what operating system?
AndroidBluetoothAPI_0.3.jar HTC tatoo 1.6

Please provide any additional information below.
Here is my source;
package com.eofisi.blueToothTest3;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import it.gerdavax.android.bluetooth.BluetoothDevice;
import it.gerdavax.android.bluetooth.LocalBluetoothDevice;
import it.gerdavax.android.bluetooth.LocalBluetoothDeviceListener;
import it.gerdavax.android.bluetooth.RemoteBluetoothDevice;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class blueToothTest3 extends Activity {

    private static final String TAG = "DeviceDiscoverySample";
    protected LocalBluetoothDevice localBluetoothDevice = null;
    protected static ProgressDialog dialog;
    protected Handler handler = new Handler();
    protected ArrayList<String> devices;
    protected AlertDialog deviceInfoDialog;

    /*@Override
    protected void onDestroy() {
       if (localBluetoothDevice != null) {
           localBluetoothDevice.close();
       }
       super.onDestroy();
    }*/
    @Override
    protected void onDestroy() {
        super.onDestroy();
        localBluetoothDevice.close();
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //get local device details

        TextView bluetoothStatusTextView = (TextView) findViewById(R.id.localDeviceBluetoothStatus);
        TextView addressTextView = (TextView) findViewById(R.id.localDeviceAddress);
        TextView friendlyNameTextView = (TextView) findViewById(R.id.localDeviceFriendlyName);

        try {
            localBluetoothDevice = LocalBluetoothDevice.initLocalDevice(this);

            if (localBluetoothDevice.isEnabled()) {
                //scan for an devices
                scanForDevices();
            } else {
                bluetoothStatusTextView.setText("Status:Disables");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void scanForDevices(){

        DeviceAdapter adapter = new DeviceAdapter();
        //setListAdapter(adapter);
        TextView bluetoothStatusTextView = (TextView) findViewById(R.id.localDeviceBluetoothStatus);
        TextView addressTextView = (TextView) findViewById(R.id.localDeviceAddress);
        TextView friendlyNameTextView = (TextView) findViewById(R.id.localDeviceFriendlyName);
        TextView descoveringDevices = (TextView) findViewById(R.id.descoveringDevices);

        try {
            //localBluetoothDevice = LocalBluetoothDevice.initLocalDevice(this);
                bluetoothStatusTextView.setText("Status:Enabled");
                String address = localBluetoothDevice.getAddress();
                if (address != null) {
                    addressTextView.setText("Address: " + address);
                }

                String name = localBluetoothDevice.getName();
                if (name != null) {
                    friendlyNameTextView.setText("Name: " + name);
                }

                localBluetoothDevice.setListener(adapter);
                descoveringDevices.setText("Decovering:True");

                try {
                    localBluetoothDevice.scan();
                } catch (Exception e) {
                    descoveringDevices.setText("Decovering:Error");
                    e.printStackTrace();
                }

        } catch (Exception e) {
        }

    } 

    protected class DeviceAdapter extends BaseAdapter implements LocalBluetoothDeviceListener {
        TextView ScanningStatus = (TextView) findViewById(R.id.ScanningStatus);
        TextView bluetoothStatusTextView = (TextView) findViewById(R.id.localDeviceBluetoothStatus);
        TextView  ScanningStarted= (TextView) findViewById(R.id.ScanningStarted);

        public int getCount() {
            if (devices != null) {
                return devices.size();
            }
            return 0;
        }

        public Object getItem(int position) {
            return devices.get(position);
        }

        public long getItemId(int position) {
            return 0;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ScanningStatus.setText("Status:View Called");
            LinearLayout feedItem = null;

            return feedItem;
        }

        public void scanCompleted(ArrayList<String> devs) {
            devices = devs;
            //notifyDataSetChanged();
            //hideProgressDialog();
            ScanningStatus.setText("Status:Scanning Complete");

            // display the number of devices
            TextView NoOfDevices = (TextView) findViewById(R.id.NoOfDevices);
            int deviceCount=devices.size();

            NoOfDevices.setText("DeviceNO:"+deviceCount);
            String address = devices.get(0);
            RemoteBluetoothDevice remoteBluetoothDevice = localBluetoothDevice.getRemoteBluetoothDevice(address);
        }

        public void scanStarted() {
            //showProgressDialog();
            ScanningStarted.setText("Scan Started");            
        }

        public void disabled() {
            bluetoothStatusTextView.setText("Blutooth:disabled");
        }

        public void enabled() {
            bluetoothStatusTextView.setText("Blutooth:Enabled");
        }

        @Override
        public void bluetoothDisabled() {
            // TODO Auto-generated method stub

        }

        @Override
        public void bluetoothEnabled() {
            // TODO Auto-generated method stub

        }

        @Override
        public void deviceFound(String arg0) {
            // TODO Auto-generated method stub
            ScanningStatus.setText("Status:Found Device");              
        }

    }    

}

Hope you can help.

Original issue reported on code.google.com by much...@gmail.com on 11 Jun 2010 at 4:39

GoogleCodeExporter commented 8 years ago
Hi,

I have same problems and came to the conclusion that the Tattoo does not 
support bluetooth to such extend which can be used by the unofficial API or 
backport. I also tried the "Bluetooth File Transfer for Android!" from 
http://www.medieval.it which explicitely states when starting the App that the 
Tattoo does not work.

Stefan

Original comment by stefanpa...@googlemail.com on 14 Jun 2010 at 6:35

GoogleCodeExporter commented 8 years ago
Hi 
Do you know how I can get the device to be on discoverable?  

Thank you !!
Bits Android Team

Original comment by bitsAndr...@gmail.com on 16 Jun 2010 at 7:17