AIM:-Write A Program That Identifies The Bluetooth Devices in The Wireless Range

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Practical :-2

AIM:- Write a program that identifies the bluetooth devices in the wireless range.

DeviceListAdapter.java

package com.example.user.bluetooth_communication;

import android.bluetooth.BluetoothDevice;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.ArrayAdapter;

import android.widget.TextView;

import java.util.ArrayList;

public class DeviceListAdapter extends ArrayAdapter<BluetoothDevice> {

private LayoutInflater mLayoutInflater;

private ArrayList<BluetoothDevice> mDevices;

private int mViewResourceId;

public DeviceListAdapter(Context context, int tvResourceId, ArrayList<BluetoothDevice>

devices){

super(context, tvResourceId,devices);

this.mDevices = devices;

mLayoutInflater = (LayoutInflater)

context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

mViewResourceId = tvResourceId;

public View getView(int position, View convertView, ViewGroup parent) {


convertView = mLayoutInflater.inflate(mViewResourceId, null);

BluetoothDevice device = mDevices.get(position);

if (device != null) {

TextView deviceName = (TextView)

convertView.findViewById(R.id.tvDeviceName);

TextView deviceAdress = (TextView)

convertView.findViewById(R.id.tvDeviceAddress);

if (deviceName != null) {

deviceName.setText(device.getName());

if (deviceAdress != null) {

deviceAdress.setText(device.getAddress());

return convertView;

You might also like