Page 105

Android Programming Cookbook

97 / 143

<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/title_paired_devices" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#666" android:paddingLeft="5dp" android:text="@string/title_paired_devices" android:textColor="#fff" android:visibility="gone" /> <ListView android:id="@+id/paired_devices" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:stackFromBottom="true" /> <TextView android:id="@+id/title_new_devices" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#666" android:paddingLeft="5dp" android:text="@string/title_other_devices" android:textColor="#fff" android:visibility="gone" /> <ListView android:id="@+id/new_devices" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:stackFromBottom="true" /> <Button android:id="@+id/button_scan" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button_scan" /> </LinearLayout>

5.7

Create the source code of the DeviceListActivity

This Activity lists any paired devices and devices detected in the area after discovery. When a device is chosen by the user, the MAC address of the device is sent back to the parent Activity in the result Intent. So, add a new Java class inside src/com.javacodegeeks.androidBluetoothExample/ so that we are going to have the src/com.javacodegeeks.androidBluetoothExample/DeviceListActivity.java file and paste the code below. DeviceListActivity.java package com.javacodegeeks.androidBluetoothExample; package com.javacodegeeks.androidBluetoothExample;

SKY MAGZ  

This is Yahya Christian School Magazine