本文介绍了bluetoothSocket.Connect()上的服务发现失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨。
在这个程序中,当我调用bluetoothSocket.Connect()时,会发生以下错误:
Java.IO.IOException:/Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3中的Android.Runtime.JNIEnv.CallVoidMethod(intptr,intptr)[0x00022]中的服务发现失败
-branch / 410a5aba / source / monodroid / src / Mono.Android / src / Runtime / JNIEnv.g.cs:356
在/ Users中的Android.Bluetooth.BluetoothSocket.Connect()[0x0002d] /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
在AndroidBluetooth.Activity1.ConnectButton_Click(object,System.EventArgs)[0x0005d]在c:\ Users \ emhammadali1375 \Documents\Projects\AndroidBluetooth\AndroidBluetooth \Activity1.cs :/ Users / builder / data /中的Android.Views.View / IOnClickListenerImplementor.OnClick(Android.Views.View)[0x0000b]中的37
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>
---托管异常堆栈跟踪结束---
java.io.IOException:服务发现失败
在android.bluetooth.BluetoothSocket $ SdpHelper.doSdp(BluetoothSocket.java:406)
在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:217)
在mono.android.view.View_OnClickListenerImplementor.n_onClick(原生方法)
在mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
在android .view.View.performClick(View.java:2485)
在android.view.View $ PerformClick.run(View.java:9080)
在android.os .Handler.handleCallback(Handler.java:587)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop (Looper.java:130)
在android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native方法)
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)
这是我的程序:
使用系统;
使用 System.IO;
使用 Android.App;
使用 Android.Content;
使用 Android.Runtime;
使用 Android.Views;
使用 Android.Widget;
使用 Android.OS;
使用 Android.Bluetooth;
命名空间 AndroidBluetooth
{
[活动(标签= AndroidBluetooth,MainLauncher = true )]
公开 类活动1:活动
{
受保护 覆盖 void OnCreate(捆绑包)
{
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 意图( 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;
}
}
}
我该怎么办?
请帮帮我。
解决方案
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; } } }
What should I do ?
Please help me.
解决方案
这篇关于bluetoothSocket.Connect()上的服务发现失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!