How To Connect To Phone And Send Files & Chat Messages Via Bluetooth?
I am creating a Android Application that will have a Menu containing two options: Chat via Bluetooth. Transfer Files via Bluetooth. Config containing controls to turn Bluetooth OF
Solution 1:
Maybe the android bluetooth tutorial can help you
And this tutorial say how you can send messages and files between devices: Bluetooth Data Transfer
But, basically: You need add this permission to your manifest.xml file:
<uses-permissionandroid:name="android.permission.BLUETOOTH"/>
And your on create event could looks like: (But all the codes are in the tutorial)
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.txDevice);
MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
ba = BluetoothAdapter.getDefaultAdapter();
if(!ba.isEnabled()){
Intentintent=newIntent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
Intentintent1=newIntent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivity(intent1);
}
Solution 2:
Google has provided a sample app to demonstrate the Bluetooth chat. You can refer it.
It is fully functional bluetooth chat application.
And to activate and deactivate bluetooth you can use this code
BluetoothAdaptermBluetoothAdapter= BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.isEnabled()) {
//deatctivate bluetooth
mBluetoothAdapter.disable();
}
//Activate bluetooth
mBluetoothAdapter.enable();
Post a Comment for "How To Connect To Phone And Send Files & Chat Messages Via Bluetooth?"