0% found this document useful (0 votes)
10 views3 pages

Bluetooth Control App Code Example

The document contains an AndroidManifest.xml file and a MainActivity.java file for a Bluetooth application. The manifest includes permissions for Bluetooth and location access, while the MainActivity manages Bluetooth functionality such as turning it on/off and discovering devices. The layout features buttons for controlling Bluetooth and a ListView for displaying paired devices.

Uploaded by

sawantkrish562
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Bluetooth Control App Code Example

The document contains an AndroidManifest.xml file and a MainActivity.java file for a Bluetooth application. The manifest includes permissions for Bluetooth and location access, while the MainActivity manages Bluetooth functionality such as turning it on/off and discovering devices. The layout features buttons for controlling Bluetooth and a ListView for displaying paired devices.

Uploaded by

sawantkrish562
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPl 24.

[Link]

<?xml version="1.0" encoding="utf-8"?>


<?xml version="1.0" encoding="utf-8"?>
<manifest
<LinearLayout
xmlns:android="[Link]
xmlns:android="[Link]
k/res/android"
k/res/android"
package="[Link]">
android:layout_width="match_parent"
<uses-permission
android:layout_height="match_parent"
android:name="[Link]"
android:paddingLeft="10dp"
/>
android:orientation="vertical"
<uses-permission
android:paddingRight="10dp">
android:name="[Link].BLUETOOTH_
<TextView
ADMIN"/>
android:layout_width="wrap_content"
<uses-permission
android:layout_height="wrap_content"
android:name="[Link].ACCESS_COA
android:text="Bluetooth"
RSE_LOCATION"/>
android:textSize="25dp"
<application
android:textStyle="bold"
android:allowBackup="true"
/>
android:icon="@mipmap/ic_launcher"
<Button
android:label="@string/app_name"
android:id="@+id/btnOn"
android:layout_width="wrap_content"
android:roundIcon="@mipmap/ic_launcher_roun
android:layout_height="wrap_content"
d"
android:text="Turn On" />
android:supportsRtl="true"
<Button
android:theme="@style/AppTheme">
android:id="@+id/btnDiscoverable"
<activity android:name=".MainActivity">
android:layout_width="wrap_content"
<intent-filter>
android:layout_height="wrap_content"
<action
android:name="[Link]" />
android:text="Get Visible" />
<category
<Button
android:name="[Link]
android:layout_width="wrap_content"
ER" />
android:layout_height="wrap_content"
</intent-filter>
android:id="@+id/btnGet"
</activity>
android:text="List Devices"
</application>
/>
<Button
</manifest>
android:id="@+id/btnOFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
[Link]
android:text="Turn OFF" />
<ListView package [Link];
android:id="@+id/deviceList"
android:layout_width="match_parent" import
android:layout_height="wrap_content" > [Link];
</ListView>
</LinearLayout> import [Link];
import [Link];
import [Link];
import [Link]; [Link](getApplicationContext(),"Bluetoot
import [Link]; h Turned OFF", Toast.LENGTH_SHORT).show();
import [Link]; }
import [Link]; });
import [Link]; [Link](new
import [Link]; [Link]() {
@Override
import [Link]; public void onClick(View v) {
import [Link]; if(![Link]()){
startActivityForResult(new
public class MainActivity extends Intent(BluetoothAdapter.ACTION_REQUEST_DISC
AppCompatActivity { OVERABLE),1);
private ListView lstvw;
private ArrayAdapter aAdapter; [Link](getApplicationContext(),"Making
private BluetoothAdapter bAdapter = Device
[Link](); Discoverable",Toast.LENGTH_SHORT).show();
@Override }
protected void onCreate(Bundle }
savedInstanceState) { });
[Link](savedInstanceState);
setContentView([Link].activity_main); Button btn =
Button btntOn = (Button)findViewById([Link]);
(Button)findViewById([Link]); [Link](new
Button btntOff = [Link]() {
(Button)findViewById([Link]); @Override
Button btnDisc = public void onClick(View v) {
(Button)findViewById([Link]); if(bAdapter==null){
final BluetoothAdapter bAdapter =
[Link](); [Link](getApplicationContext(),"Bluetoot
[Link](new h Not Supported",Toast.LENGTH_SHORT).show();
[Link]() { }
@Override else{
public void onClick(View v) { Set<BluetoothDevice> pairedDevices =
if(bAdapter == null) [Link]();
{ ArrayList list = new ArrayList();
if([Link]()>0){
[Link](getApplicationContext(),"Bluetoot for(BluetoothDevice device:
h Not Supported",Toast.LENGTH_SHORT).show(); pairedDevices){
} String devicename =
else{ [Link]();
if(![Link]()){ String macAddress =
startActivityForResult(new [Link]();
Intent(BluetoothAdapter.ACTION_REQUEST_ENAB [Link]("Name:
LE),1); "+devicename+"MAC Address: "+macAddress);
}
[Link](getApplicationContext(),"Bluetoot lstvw = (ListView)
h Turned ON",Toast.LENGTH_SHORT).show(); findViewById([Link]);
} aAdapter = new
} ArrayAdapter(getApplicationContext(),
} [Link].simple_list_item_1, list);
}); [Link](aAdapter);
[Link](new }
[Link]() { }
@Override }
public void onClick(View v) { });
[Link](); }
}

You might also like