Принтер этикеток Zebra в Mono для Android вызывает неожиданный сбой без исключений

Я создал приложение Mono для Android, которое использует API печати Zebra. Мне удалось получить ссылку на файл ZSDK_API.jar как в библиотеке привязок Java, так и в приложении Standard Mono для Android, как определено ЗДЕСЬ

  • Я добавил файл .jar в проект JBL (папка Jars) и установил действие сборки на InputJar.
  • Я также добавил банку в приложение Mono для 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;
    }
}

Я убедился, что манифест запрашивает Bluetooth и Bluetooth_Admin, а также Интернет.

Приложение создается, но при запуске просто вылетает, никаких исключений и просто пишет "Приложение неожиданно остановлено"

Все классы обнаруживаются и компилируются, но я понятия не имею, почему это так бомбит. Кому-нибудь удалось интегрировать Mono для Android — Zebra?


person Quintin Balsdon    schedule 16.11.2012    source источник


Ответы (1)


Черт возьми - я отбивная! Как только я опубликовал его, я подумал - вероятно, это как-то связано с тем фактом, что я реализовывал IntPtr Handle в качестве дескриптора родителя - я был прав. Вот первый шаг рабочего кода (ПЕРВЫЙ ШАГ - если мне нужно ответить на свои вопросы!):

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

}

person Quintin Balsdon    schedule 16.11.2012