I am creating an application which can send data to a Bluetooth device. I used the following code to create and connect socket:
package com.example.bluetooth; import java.io.IOException; import java.util.UUID; import android.os.Bundle; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.util.Log; import android.view.Menu; import android.widget.Toast; public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice bd = ba.getRemoteDevice("20:13:10:15:39:84"); Toast.makeText(getApplicationContext(), bd.getName(), Toast.LENGTH_SHORT).show(); BluetoothSocket bs = null; try{ bs = bd.createInsecureRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch(IOException io){ Toast.makeText(getApplicationContext(), "Socket Create : " + io.toString() , Toast.LENGTH_SHORT).show(); } try{ ba.cancelDiscovery(); bs.connect(); } catch(IOException io){ Log.e("Socket Connect", io.toString()); Toast.makeText(getApplicationContext(), "Socket Connect : " + io.toString() , Toast.LENGTH_LONG).show(); } } } My problem is that socket is not being connected. The message displayed is "java.io.IOException: [JSR82] connect: Connection is not created (failed or aborted)."
I am using android 4.2 Lenovo Device.
The Bluetooth Module used is HC-05 and microcontroller is Arduino-Uno.
I have have referred to similar posts but none could solve my problem.
Thanks in Advance