Bluetooth Android版Mono中的Zebra标签打印机导致意外崩溃,无例外

Bluetooth Android版Mono中的Zebra标签打印机导致意外崩溃,无例外,bluetooth,xamarin.android,zebra-printers,Bluetooth,Xamarin.android,Zebra Printers,我已经为Android创建了一个Mono应用程序,它使用Zebra打印API。我已经成功地获得了Java绑定库和Android标准Mono应用程序中引用的ZSDK_API.jar文件 我已将.jar文件添加到JBL项目(Jars文件夹),并将其构建操作设置为InputJar 我还将jar添加到Mono for Android应用程序中,并将构建操作设置为AndroidJavaLibrary 发现手柄 public class DiscoveryHandler : IDiscoveryHand

我已经为Android创建了一个Mono应用程序,它使用Zebra打印API。我已经成功地获得了Java绑定库和Android标准Mono应用程序中引用的ZSDK_API.jar文件

  • 我已将.jar文件添加到JBL项目(Jars文件夹),并将其构建操作设置为InputJar
  • 我还将jar添加到Mono for Android应用程序中,并将构建操作设置为AndroidJavaLibrary
发现手柄

public class DiscoveryHandler : IDiscoveryHandler
{
    private Discovery _reference;

    public DiscoveryHandler(Discovery reference)
    {
        _reference = reference;
    }

    public void DiscoveryError(string message)
    {
        new UIHelper(_reference).showErrorDialogOnGuiThread(message);
    }

    public void DiscoveryFinished()
    {
        _reference.RunOnUiThread(() =>
        {
            Toast.MakeText(_reference, " Discovered " + _reference.discoveredPrinters.Count + " devices", ToastLength.Short).Show();
            _reference.SetProgressBarIndeterminateVisibility(false);
        });
    }

    public void FoundPrinter(DiscoveredPrinter printer)
    {
        _reference.RunOnUiThread(() => 
        {
            DiscoveredPrinterBluetooth p = (DiscoveredPrinterBluetooth)printer;
            _reference.discoveredPrinters.Add(p.Address + " (" + p.FriendlyName + ")");
            _reference.mArrayAdapter.NotifyDataSetChanged();
        }); 
    }

    public void Dispose()
    {

    }

    public IntPtr Handle
    {
        get { return _reference.Handle; }
    }
}
Discovery.cs

public class Discovery : ListActivity
{
    public List<string> discoveredPrinters = null;
    public ArrayAdapter<string> mArrayAdapter;
    private static IDiscoveryHandler btDiscoveryHandler = null;


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        RequestWindowFeature(WindowFeatures.IndeterminateProgress);
        SetContentView(Resource.Layout.discovery_results);

        SetProgressBarIndeterminateVisibility(true);
        discoveredPrinters = new List<string>();
        SetupListAdapter();
        btDiscoveryHandler = new DiscoveryHandler(this);

        try
        {
            new Thread(new ThreadStart(() =>
                {
                    Looper.Prepare();

                    try
                    {
                        RunOnUiThread(() => Toast.MakeText(this, "Trying", ToastLength.Short).Show());
                        BluetoothDiscoverer.FindPrinters(this, btDiscoveryHandler);
                        RunOnUiThread(() => Toast.MakeText(this, "And...", ToastLength.Short).Show());
                    }
                    catch (ZebraPrinterConnectionException zex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(zex.Message);
                    }
                    catch (ThreadInterruptedException iex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(iex.Message);
                    }
                    catch (Exception ex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(ex.Message);
                    }
                    finally
                    {
                        RunOnUiThread(() => Toast.MakeText(this, "Quitting looper", ToastLength.Short).Show());
                        Looper.MyLooper().Quit();
                        RunOnUiThread(() => Toast.MakeText(this, "Finished", ToastLength.Short).Show());
                    }
                })).Start();
        }
        catch (Exception ex)
        {
            new UIHelper(this).showErrorDialogOnGuiThread(ex.Message);
        }            
    }

    private void SetupListAdapter()
    {
        mArrayAdapter = new ArrayAdapter<string>(this, global::Android.Resource.Layout.SimpleListItem1, discoveredPrinters);
        ListAdapter = mArrayAdapter;
    }
}
公共类发现:ListActivity
{
public List discoveredPrinters=null;
公共ArrayaAdapter MarrayaAdapter;
私有静态IDiscoveryHandler btDiscoveryHandler=null;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.UndeterminateProgress);
SetContentView(Resource.Layout.discovery\u结果);
SetProgressBarInDeterminateVibility(真);
discoveredPrinters=新列表();
SetupListAdapter();
btDiscoveryHandler=新的DiscoveryHandler(本);
尝试
{
新线程(新线程开始(()=>
{
Looper.Prepare();
尝试
{
RunOnUiThread(()=>Toast.MakeText(这是“尝试”,ToastLength.Short).Show());
Bluetooth Discoverer.findprants(这个,btDiscoveryHandler);
RunOnUiThread(()=>Toast.MakeText(这是“And…”,ToastLength.Short).Show());
}
捕获(ZebraPrinterConnectionException zex)
{
新UIHelper(this.showErrorDialogOnGuiThread)(zex.Message);
}
捕获(ThreadInterruptedException iex)
{
新UIHelper(this.showerRorDialogOnUIThread)(iex.Message);
}
捕获(例外情况除外)
{
新UIHelper(this.batherRorDialogOnUIThread)(例如Message);
}
最后
{
RunOnUiThread(()=>Toast.MakeText(这是“退出活套”,ToastLength.Short).Show());
Looper.MyLooper().Quit();
RunOnUiThread(()=>Toast.MakeText(这个“Finished”,ToastLength.Short).Show());
}
})).Start();
}
捕获(例外情况除外)
{
新UIHelper(this.batherRorDialogOnUIThread)(例如Message);
}            
}
私有void SetupListAdapter()
{
mArrayAdapter=newarrayadapter(这个,全局::Android.Resource.Layout.SimpleListItem1,discoveredPrinters);
ListAdapter=mArrayAdapter;
}
}
我已经确定清单要求蓝牙和蓝牙管理以及互联网

应用程序会生成,但运行时会崩溃,没有异常,只是说“应用程序意外停止”


所有的类都被检测和编译,但我不知道为什么会这样。有人成功地将Mono与Android-Zebra集成在一起了吗?

该死,我真是个傻瓜!就在我发布它的时候,我开始思考——这可能与我将IntPtr句柄实现为父级句柄的事实有关——我是对的。下面是工作代码的第一步(第一步-如果我必须回答自己的问题!):

公共类发现:ListActivity,IDiscoveryHandler
{
public List discoveredPrinters=null;
公共ArrayaAdapter MarrayaAdapter;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.UndeterminateProgress);
SetContentView(Resource.Layout.discovery\u结果);
SetProgressBarInDeterminateVibility(真);
discoveredPrinters=新列表();
SetupListAdapter();
尝试
{
新线程(新线程开始(()=>
{
Looper.Prepare();
尝试
{                            
蓝牙发现者。FindPrintes(这个,这个);
}
捕获(ZebraPrinterConnectionException zex)
{
新UIHelper(this.showErrorDialogOnGuiThread)(zex.Message);
}
捕获(ThreadInterruptedException iex)
{
新UIHelper(this.showerRorDialogOnUIThread)(iex.Message);
}
捕获(例外情况除外)
{
新UIHelper(this.batherRorDialogOnUIThread)(例如Message);
}
最后
{
RunOnUiThread(()=>Toast.MakeText(这是“退出活套”,ToastLength.Short).Show());
Looper.MyLooper().Quit();
RunOnUiThread(()=>Toast.MakeText(这个“Finished”,ToastLength.Short).Show());
}
})).Start();
}
捕获(例外情况除外)
{
新UIHelper(this.batherRorDialogOnUIThread)(例如Message);
}            
}
私有void SetupListAdapter()
{
mArrayAdapter=newarrayadapter(这个,全局::Android.Resource.Layout.SimpleListItem1,discoveredPrinters);
ListAdapter=mArrayAdapter;
}
public void DiscoveryError(字符串消息)
{
新UIHelper(this).batherRorDialogOnUIThread(消息);
}
公共无效发现完成()
{
RunOnUiThread(()=>
{
Toast.MakeText(这个“Discovered”+Discovered
public class Discovery : ListActivity, IDiscoveryHandler
{
    public List<string> discoveredPrinters = null;
    public ArrayAdapter<string> mArrayAdapter;        

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        RequestWindowFeature(WindowFeatures.IndeterminateProgress);
        SetContentView(Resource.Layout.discovery_results);

        SetProgressBarIndeterminateVisibility(true);
        discoveredPrinters = new List<string>();
        SetupListAdapter();            

        try
        {
            new Thread(new ThreadStart(() =>
                {
                    Looper.Prepare();

                    try
                    {                            
                        BluetoothDiscoverer.FindPrinters(this, this);                         
                    }
                    catch (ZebraPrinterConnectionException zex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(zex.Message);
                    }
                    catch (ThreadInterruptedException iex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(iex.Message);
                    }
                    catch (Exception ex)
                    {
                        new UIHelper(this).showErrorDialogOnGuiThread(ex.Message);
                    }
                    finally
                    {
                        RunOnUiThread(() => Toast.MakeText(this, "Quitting looper", ToastLength.Short).Show());
                        Looper.MyLooper().Quit();
                        RunOnUiThread(() => Toast.MakeText(this, "Finished", ToastLength.Short).Show());
                    }
                })).Start();
        }
        catch (Exception ex)
        {
            new UIHelper(this).showErrorDialogOnGuiThread(ex.Message);
        }            
    }

    private void SetupListAdapter()
    {
        mArrayAdapter = new ArrayAdapter<string>(this, global::Android.Resource.Layout.SimpleListItem1, discoveredPrinters);
        ListAdapter = mArrayAdapter;
    }

    public void DiscoveryError(string message)
    {
        new UIHelper(this).showErrorDialogOnGuiThread(message);
    }

    public void DiscoveryFinished()
    {
        RunOnUiThread(() =>
        {
            Toast.MakeText(this, " Discovered " + discoveredPrinters.Count + " devices", ToastLength.Short).Show();
            SetProgressBarIndeterminateVisibility(false);
        });
    }

    public void FoundPrinter(DiscoveredPrinter printer)
    {
        RunOnUiThread(() =>
        {

            DiscoveredPrinterBluetooth p = printer.JavaCast<DiscoveredPrinterBluetooth>();
            discoveredPrinters.Add(p.Address + " (" + p.FriendlyName + ")");
            mArrayAdapter.NotifyDataSetChanged();
        }); 
    }
}