Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:48:38+00:00 2026-06-10T10:48:38+00:00

I read lots of things about bluetooth on the Android Developer website, but I

  • 0

I read lots of things about bluetooth on the Android Developer website, but I can’t understand one thing though, how do I start a connection with a paired (or bonded) device with his mac address that I got in a ListView.
Just to see if my code worked (the OnItemClickListner part), I use a button to display the mac address.
But what I want to do is using OnItemClickListener to initiate a connection with the selected Device.
(I hope my explanations are clear)

Here is my code at least one part of it.
http://pastie.org/4591835

Thing is I don’t know how to use the rfcomm thingy in order to do what I want to do.

Could someone explain this to me please ?

The purpose of my code is to connect my android phone to my Arduino and send letters to it through some buttons
eg : The button Led 1 would send “A” to my arduino and so on.

Thanks in advance !

    package com.jon.arduino.remote;

import java.util.Set;
import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;


public class NextActivity extends Activity {

    // Variables & constantes
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    private ArrayAdapter<String> deviceslist;
    public static String EXTRA_DEVICE_ADDRESS = "device_address";





    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_list);
        setupUI();
        searchbtdevices();
    }


    /////////////////////////////////////////////////////////////////// 
    private void searchbtdevices() {


        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        // If there are paired devices
        if (pairedDevices.size() > 0) {
            // Loop through paired devices
            for (BluetoothDevice device : pairedDevices) {
                // Add the name and address to an array adapter to show in a ListView
                deviceslist.add(device.getName() + "\n" + device.getAddress());
                                                         }
                                        } 


                           }


    /////////////////////////////////////////////////////////////////// 
    /*private void connecttobt() 
    {


    }*/


    /////////////////////////////////////////////////////////////////// 
    private void setupUI() {


        final Button btnmacaddress = (Button) findViewById(R.id.btnmacaddress);
        final ListView bt_deviceslist = (ListView) findViewById(R.id.bt_deviceslist);
        deviceslist = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
        bt_deviceslist.setAdapter(deviceslist);


        bt_deviceslist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
               public void onItemClick(AdapterView<?> list, View v, int pos, long id) {

                   mBluetoothAdapter.cancelDiscovery();
                   String info = ((TextView) v).getText().toString();

                        // Attempt to extract a MAC address
                        String macaddress = info.substring(info.length() - 17);

                        // Create the result Intent and include the MAC address
                        Intent intent = new Intent();
                        intent.putExtra(EXTRA_DEVICE_ADDRESS, macaddress);

                        mBluetoothAdapter.cancelDiscovery();
                    //  connecttobt();



                        btnmacaddress.setText(macaddress);
                                                                                    }});                
                            }
    ///////////////////////////////////////////////////////////////////                                                                                 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:48:39+00:00Added an answer on June 10, 2026 at 10:48 am

    I have done something similar to what you want to do and have two examples that can be found at:

    http://digitalhacksblog.blogspot.com/2012/05/arduino-to-android-basic-bluetooth.html

    http://digitalhacksblog.blogspot.com/2012/05/arduino-to-android-turning-led-on-and.html

    The first example shows how to send text from Android to an Arduino using a program called BlueTerm. This shows the basic setup for both the Android and Arduino to get them to communicate.

    The second example is a program on Android that turns on and off LEDs on an Arduino. This shows how to communicated between the two devices from a program.

    The examples have all the code necessary both for Android and the Arduino.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read lots about the Microsoft's threaded apartment model, but I'm still having a
OK. I've read things here and there about SQL Server heaps, but nothing too
LOTS of Default.png Q's, but I didn't read one like this: I see Default.png,
I have read lots of questions and answers about this issue on StackOverflow, but
I've read the documentation and I've tried lots of things in the REPL, and
I am stuck with connecting to Oracle DB, have read lots of stuff but
Can someone explain to me why this doesn't work? I've read lots of posts
There are lots written about the ReaderWriterLockSlim class which allows multiple read and a
I read lot's of docs, tried everything and still can't understand why my template
After a lots of read about Repository and Data Mapper I decided to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.