Oh, you're not using the BluetoothAdapter correctly... You basically call
"startdiscovery" and then display stuff.  That's not how it works.  It's an
asynchronous call.  You start discovery with .startDiscovery() and then you
have to wait until it's finished.  To handle that, you wait for a broadcast
action (ACTION_DISCOVERY_FINISHED) to be sent, you have to register a
broadcastreciever to deal with that.


You can read all about this in the BluetoothAdapter API documentation,
that's where I suggest you start.  There's also a Bluetooth demo somewhere,
not sure if it works for more recent devices, but I remember to have gotten
it working on the Hero a long time ago (that being said, BT on the older
HTCs was always somewhat flaky for me).


kris


On Thu, Feb 9, 2012 at 11:13 AM, Soyer <mblack...@gmail.com> wrote:

> Hello Kris, i tried it on a mobile phone (HTC Hero) and no detected
> devices were displayed...it's showing the default bluetooth adapter,
> and then "Start discovering", "Done with discovery" and at last:
> "Devices paired:          " and nothing displayed, though my other
> mobile phone is next to it.
>
> On Feb 9, 7:41 pm, Kristopher Micinski <krismicin...@gmail.com> wrote:
> > Did you try running this in a debugger to see what's going on?
> >
> > kris
> >
> >
> >
> >
> >
> >
> >
> > On Thu, Feb 9, 2012 at 9:58 AM, Soyer <mblack...@gmail.com> wrote:
> > > Sure, first bluetooth detection on Android emulator is not supported
> > > on Wind7 so i used VirtualBox to run it on Linux2.4, so the bluetooth
> > > features are supported by the Host OS and the emulator, but the thing
> > > is that the app is not detecting any devices (My phone...)
> >
> > > This is my code:
> > > package android.mgo.helloandroid;
> >
> > > import java.util.Set;
> >
> > > import android.app.Activity;
> > > import android.content.Intent;
> > > import android.os.Bundle;
> > > import android.view.View;
> > > import android.view.View.OnClickListener;
> > > import android.widget.Button;
> > > import android.widget.EditText;
> > > import android.bluetooth.BluetoothAdapter;
> > > import android.bluetooth.BluetoothDevice;
> > > import android.content.Intent;
> >
> > > public class UIdrawingActivity extends Activity implements
> > > OnClickListener {
> > >    /** Called when the activity is first created. */
> >
> > >        Button startdetectingbtn;
> > >        Button clearbtn;
> > >    EditText roomnumbertext;
> > >    EditText  bluetoothdetect;
> > >    @Override
> > >    public void onCreate(Bundle savedInstanceState) {
> > >        super.onCreate(savedInstanceState);
> > >        setContentView(R.layout.main);
> > >        bluetoothdetect = (EditText)findViewById(R.id.detectedsignal);
> >
> > >      clearbtn = (Button)findViewById(R.id.clearbtn);
> >
> > >        View startdetectingbtn = findViewById(R.id.startdetectingbtn);
> > >        startdetectingbtn.setOnClickListener(this);
> >
> > >         clearbtn.setOnClickListener(new OnClickListener() {
> > >     //         clear the text boxes
> > >     @Override
> > >      public void onClick(View v) {
> >
> > >      bluetoothdetect.setText("");
> >
> > >      }
> >
> > >      });}
> >
> > >         @Override
> > >                public void onClick(View v) {
> >
> > >                        switch (v.getId()) {
> > >                case R.id.startdetectingbtn:
> >
> > >              EditText bluetoothtext =
> > > (EditText)findViewById(R.id.detectedsignal);
> >
> > >                           // Getting the Bluetooth adapter
> > >                 BluetoothAdapter adapter =
> > > BluetoothAdapter.getDefaultAdapter();
> > >                           bluetoothtext.append("\nAdapter: " +
> adapter);
> >
> > >                 // Check for Bluetooth support in the first place
> > >                 // Emulator doesn't support Bluetooth and will return
> null
> > >                 if(adapter==null) {
> > >                   bluetoothtext.append("\nBluetooth NOT supported.
> > > Aborting.");
> > >                      return;
> > >                                    }
> > >                 else{
> > >                 // Starting the device discovery
> > >                         bluetoothtext.append("\nStarting
> discovery...");
> > >                           adapter.startDiscovery();
> > >                           bluetoothtext.append("\nDone with
> discovery...");
> >
> > >                 // Listing paired devices
> > >                           bluetoothtext.append("\nDevices Paired:");
> > >                           Set<BluetoothDevice> devices =
> > > adapter.getBondedDevices();
> > >                           for (BluetoothDevice device : devices)
> > >                           {
> > >                                   bluetoothtext.append("\nFound
> device: "
> > > + device);
> >
> > >                         }
> >
> > >                         }
> > >                        }
> >
> > >         }
> >
> > > }
> >
> > > and the following is Manifest.xml file:
> >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <manifest xmlns:android="http://schemas.android.com/apk/res/android";
> > >    package="android.mgo.helloandroid"
> > >    android:versionCode="1"
> > >    android:versionName="1.0" >
> >
> > >    <uses-sdk android:minSdkVersion="3" />
> >
> > >    <application
> > >        android:icon="@drawable/ic_launcher"
> > >        android:label="@string/app_name" >
> >
> > >        <activity
> > >            android:label="@string/app_name"
> > >            android:name=".UIdrawingActivity" >
> > >            <intent-filter >
> > >                <action android:name="android.intent.action.MAIN" />
> > >                <category
> > > android:name="android.intent.category.LAUNCHER" />
> > >            </intent-filter>
> > >        </activity>
> >
> > >    </application>
> > >  <uses-permission android:name="android.permission.BLUETOOTH" />
> > >            <uses-permission
> > > android:name="android.permission.BLUETOOTH_ADMIN" />
> > > </manifest>
> >
> > > On Feb 9, 6:29 pm, TreKing <treking...@gmail.com> wrote:
> > > > On Thu, Feb 9, 2012 at 5:42 AM, Soyer <mblack...@gmail.com> wrote:
> > > > > the issue now is that i don't know why it is not listing any
> detected
> > > > > devices.
> >
> > > > > Any Ideas?
> >
> > > > Elaborate on your problem. There is almost no information here for
> anyone
> > > > to help you.
> >
> > >
> ---------------------------------------------------------------------------
> > > ----------------------
> > > > TreKing <http://sites.google.com/site/rezmobileapps/treking> -
> Chicago
> > > > transit tracking app for Android-powered devices
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to
> android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Reply via email to