Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Service discovery failed on bluetoothSocket.Connect()

$
0
0

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 :

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;
        }
    }
}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>