Zebra 印刷 API を使用する Mono for Android アプリケーションを作成しました。ここで定義されているように、Java Bindings Library と Android アプリケーション用の標準 Mono の両方で参照される ZSDK_API.jar ファイルを取得することができました。
- .jar ファイルを JBL プロジェクト (Jars フォルダー) に追加し、そのビルド アクションを InputJar に設定しました。
- また、ビルド アクションを AndroidJavaLibrary に設定して、Mono for Android アプリケーションに jar を追加しました。
DiscoveryHandler
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 for Android - Zebra の統合で成功した人はいますか?