Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.
In this program when i call bluetoothSocket.Connect() this error happen :

Java.IO.IOException: Service discovery failed
  at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00022] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:356

  at Android.Bluetooth.BluetoothSocket.Connect () [0x0002d] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Bluetooth.BluetoothSocket.cs:72

  at AndroidBluetooth.Activity1.ConnectButton_Click (object,System.EventArgs) [0x0005d] in c:\Users\mohammadali1375\Documents\Projects\AndroidBluetooth\AndroidBluetooth\Activity1.cs:37

  at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000b] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:629

  at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:600

  at (wrapper dynamic-method) object.b05cb9ef-ea88-414d-bea0-d7bd33b4de9c (intptr,intptr,intptr) <IL 0x00012, 0x00033>

  

  --- End of managed exception stack trace ---

  java.io.IOException: Service discovery failed

  	at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:406)

  	at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:217)

  	at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)

  	at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)

  	at android.view.View.performClick(View.java:2485)

  	at android.view.View$PerformClick.run(View.java:9080)

  	at android.os.Handler.handleCallback(Handler.java:587)

  	at android.os.Handler.dispatchMessage(Handler.java:92)

  	at android.os.Looper.loop(Looper.java:130)

  	at android.app.ActivityThread.main(ActivityThread.java:3687)

  	at java.lang.reflect.Method.invokeNative(Native Method)

  	at java.lang.reflect.Method.invoke(Method.java:507)

  	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)

  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

  	at dalvik.system.NativeStart.main(Native Method)


and this is my program :
C#
using System;
using System.IO;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Bluetooth;

namespace AndroidBluetooth
{
	[Activity (Label = "AndroidBluetooth", MainLauncher = true)]
	public class Activity1 : Activity
	{
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.Main);
			Button connectButton = FindViewById<Button>(Resource.Id.ConnectButton);
			connectButton.Click += ConnectButton_Click;
		}

		void ConnectButton_Click (object sender, EventArgs e)
		{
			BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
			TextView topStatusTextView = FindViewById<TextView> (Resource.Id.TopStatusTextView);
			if (!bluetoothAdapter.IsEnabled) {
				Intent enableBluetooth = new Intent (BluetoothAdapter.ActionRequestEnable);
				StartActivityForResult (enableBluetooth, 1);
			}													
			Java.Util.UUID serialUUID = Java.Util.UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");
			BluetoothDevice bluetoothDevice = bluetoothAdapter.GetRemoteDevice ("00:26:5E:DE:7D:FC");
			BluetoothSocket bluetoothSocket = null;
			Stream outStream = null;
			bluetoothSocket = bluetoothDevice.CreateRfcommSocketToServiceRecord (serialUUID);	
			bluetoothSocket.Connect();
			outStream = bluetoothSocket.OutputStream;
		}
	}
}


What should I do ?
Please help me.
Posted
Updated 8-Aug-13 11:36am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900